home *** CD-ROM | disk | FTP | other *** search
/ PC Home 119 / PC Home issue 119.iso / Software / Essentials / hotdog65demo.exe / %SYS32% / Doc5.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-12-03  |  192.3 KB  |  6,053 lines

  1. unit fDoc;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ComCtrls, Menus, uMenu, uOptions, OleCtrls, OleCtl, uSausage, uRegistry,
  8.   uText, Printers, Buttons, frstatus, ExtCtrls,  TMultiP, uInternetFiles,
  9.   sauscomb, WinSplit, uFrameRover, fColorPicker, CURLHistory, grids, HTMLEditViewLibrary_TLB, uHotDog4;
  10.  
  11. type
  12.  
  13. {-= MrKistic - 7 October 1997 =-}
  14. {-= Inline Rover Stuff =-}
  15.  
  16.   TfrmDoc = class(TForm)
  17.     dlgReplace: TReplaceDialog;
  18.     popViewMain: TPopupMenu;
  19.     popMainEdit: TMenuItem;
  20.     nMainEdit: TMenuItem;
  21.     popMainCut: TMenuItem;
  22.     popMainCopy: TMenuItem;
  23.     popMainPaste: TMenuItem;
  24.     popMainDelete: TMenuItem;
  25.     popMainUndo: TMenuItem;
  26.     popMainRedo: TMenuItem;
  27.     N20: TMenuItem;
  28.     Poste_restante: TMenuItem;
  29.     timActivate: TTimer;
  30.     timAutoSave: TTimer;
  31.     popMainPreview: TMenuItem;
  32.     popEditColor: TMenuItem;
  33.     rtfDoc: THTMLEditView;
  34.     popMainHREF: TMenuItem;
  35.     popPSP: TMenuItem;
  36.     n9: TMenuItem;
  37.     popMainFormat: TMenuItem;
  38.     mnuRelToAbs: TMenuItem;
  39.     mnuAbsToRel: TMenuItem;
  40.     n8: TMenuItem;
  41.     mnuConvertLower: TMenuItem;
  42.     mnuConvertUpper: TMenuItem;
  43.     n7: TMenuItem;
  44.     mnuTagsLowercase: TMenuItem;
  45.     mnuTagsUppercase: TMenuItem;
  46.     n6: TMenuItem;
  47.     mnuTable: TMenuItem;
  48.     mnuBList: TMenuItem;
  49.     mnuMacros: TMenuItem;
  50.     n99: TMenuItem;
  51.     mnuStripTags: TMenuItem;
  52.     panButtons: TPanel;
  53.     spdSyntax: TSpeedButton;
  54.     spdTag: TSpeedButton;
  55.     spdGutter: TSpeedButton;
  56.     spdWordWrap: TSpeedButton;
  57.     spdFields: TSpeedButton;
  58.     spdInsert: TSpeedButton;
  59.     spdFormat: TSpeedButton;
  60.     btnShowButtons: TSpeedButton;
  61.     lblDocWeight: TLabel;
  62.     popMainSmartPaste: TMenuItem;
  63.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  64.     function CheckSave: Word;
  65.     procedure FormCreate(Sender: TObject);
  66.     procedure dlgFindFind(Sender: TObject);
  67.     procedure dlgReplaceFind(Sender: TObject);
  68.     procedure dlgReplaceReplace(Sender: TObject);
  69.     procedure FormActivate(Sender: TObject);
  70.     procedure SetDisplay;
  71.     procedure Center1Click(Sender: TObject);
  72.     procedure rtfDocDragOver(Sender, Source: TObject; X, Y: Integer;
  73.       State: TDragState; var Accept: Boolean);
  74.     procedure rtfDocSelectionChanged(Sender: TObject; nStart,
  75.       nEnd: Integer);
  76.     procedure rtfDocDragDrop(Sender, Source: TObject; X, Y: Integer);
  77.     procedure popMainEditClick(Sender: TObject);
  78.     procedure lmdDocMRUClick(Sender: TObject; const aValue: string;
  79.       var Remove: Boolean);
  80.     procedure rtfDocMouseDown(Sender: TObject; Button: TMouseButton;
  81.       Shift: TShiftState; X, Y: Integer);
  82.     procedure rtfDocMouseUp(Sender: TObject; Button: TMouseButton;
  83.       Shift: TShiftState; X, Y: Integer);
  84.     procedure rtfDocKeyDown(Sender: TObject; var Key: Word;
  85.       Shift: TShiftState);
  86.     procedure rtfDocEditModeToggled(Sender: TObject; bOverwrite: Wordbool);
  87.     procedure rtfDocDocumentChanged(Sender: TObject; nAction: Smallint;
  88.       nChangeAt, nChangeCount: Integer);
  89.     procedure popViewMainPopup(Sender: TObject);
  90.     procedure popMainUndoClick(Sender: TObject);
  91.     procedure popMainRedoClick(Sender: TObject);
  92.     procedure popMainCutClick(Sender: TObject);
  93.     procedure popMainCopyClick(Sender: TObject);
  94.     procedure popMainPasteClick(Sender: TObject);
  95.     procedure popMainDeleteClick(Sender: TObject);
  96.     procedure timActivateTimer(Sender: TObject);
  97.     procedure FormShow(Sender: TObject);
  98.     procedure timAutoSaveTimer(Sender: TObject);
  99.     procedure PreviewImageClick(Sender : TObject);
  100.     function PreviewImage(sFilename : String) : String;
  101.     procedure spdSyntaxClick(Sender: TObject);
  102.     procedure spdTagClick(Sender: TObject);
  103.     procedure spdWordWrapClick(Sender: TObject);
  104.     procedure spdFieldsClick(Sender: TObject);
  105.     procedure spdInsertClick(Sender: TObject);
  106.     procedure spdFormatClick(Sender: TObject);
  107.     procedure popEditColorClick(Sender: TObject);
  108.     procedure spdGutterClick(Sender: TObject);
  109.     procedure popMainHREFClick(Sender: TObject);
  110.     procedure FormKeyUp(Sender: TObject; var Key: Word;
  111.       Shift: TShiftState);
  112.     procedure popHideGutterClick(Sender: TObject);
  113.     procedure popShowPawsClick(Sender: TObject);
  114.     procedure popLine0Click(Sender: TObject);
  115.     procedure popLine1Click(Sender: TObject);
  116.     procedure popLine2Click(Sender: TObject);
  117.     procedure popLine3Click(Sender: TObject);
  118.     procedure popLine4Click(Sender: TObject);
  119.     procedure popPSPClick(Sender: TObject);
  120.     procedure mnuRelToAbsClick(Sender: TObject);
  121.     procedure mnuAbsToRelClick(Sender: TObject);
  122.     procedure mnuConvertLowerClick(Sender: TObject);
  123.     procedure mnuConvertUpperClick(Sender: TObject);
  124.     procedure mnuTagsLowercaseClick(Sender: TObject);
  125.     procedure mnuTagsUppercaseClick(Sender: TObject);
  126.     procedure mnuTableClick(Sender: TObject);
  127.     procedure mnuBListClick(Sender: TObject);
  128.     procedure rtfDocRequestURL(Sender: TObject; var bDispatched: WordBool;
  129.       var strURL: WideString; var bAccepted: WordBool);
  130.     procedure rtfDocRequestFont(Sender: TObject; var bDispatched: WordBool;
  131.       var strFont: WideString; var bAccepted: WordBool);
  132.     procedure rtfDocRequestSound(Sender: TObject;
  133.       var bDispatched: WordBool; var strSound: WideString;
  134.       var bAccepted: WordBool);
  135.     procedure rtfDocRequestPicture(Sender: TObject;
  136.       var bDispatched: WordBool; var strPicture: WideString;
  137.       var bAccepted: WordBool);
  138.     procedure rtfDocRequestJava(Sender: TObject; var bDispatched: WordBool;
  139.       var strJava: WideString; var bAccepted: WordBool);
  140.     procedure rtfDocRequestHTML(Sender: TObject; var bDispatched: WordBool;
  141.       var strHTML: WideString; var bAccepted: WordBool);
  142.     procedure rtfDocRequestDirectory(Sender: TObject;
  143.       var bDispatched: WordBool; var strDirectory: WideString;
  144.       var bAccepted: WordBool);
  145.     procedure rtfDocSyntaxObjectChanged(Sender: TObject; nType: Smallint;
  146.       const strPrimary, strSecondary: WideString);
  147.     procedure mnuStripTagsClick(Sender: TObject);
  148.     procedure rtfDocRequestColor(Sender: TObject;
  149.       var bDispatched: WordBool; var Color: Cardinal;
  150.       var bAccepted: WordBool);
  151.     procedure btnShowButtonsClick(Sender: TObject);
  152.     procedure lblDocWeightMouseDown(Sender: TObject; Button: TMouseButton;
  153.       Shift: TShiftState; X, Y: Integer);
  154.     procedure popMainSmartPasteClick(Sender: TObject);
  155.  
  156.   private
  157.     { Private declarations }
  158.     bFirstLoaded : Boolean; 
  159.     bSetup: Boolean;
  160.     bActive: Boolean;
  161.  
  162.     sDocFileName: String;
  163.     sBackupFileName: String;
  164.  
  165.     { Find and Replace }
  166.       iLastFind: Integer;
  167.  
  168.     iReplaceCount: Integer;
  169.     iUntitledCount: Integer;
  170.     //iChildNum: Integer;
  171.  
  172.     { Spell Check }
  173.     iSpellStart, iSpellEnd: Integer;
  174.     iSpellPos: Integer;
  175.  
  176.     { Remote File Editing }
  177.     //sPWD: String;
  178.     //sRemoteFileName: String;
  179.  
  180.     //tInternetFileInfo: FTP_FILE_INFO;
  181.     //tInternetSiteInfo: FTP_SITE_INFO;
  182.     //sInternetSiteName: String;
  183.     sInternetFileName: String;
  184.     bInternet: Boolean;
  185.     tInternetServer: FTP_SITE_INFO;
  186.  
  187.     { Right Click Menu }
  188.     tCurrentElement: TElementDetails;
  189.  
  190.     { Document updating }
  191.     bDocDirty: Boolean;
  192.  
  193.     { Rover updating }
  194.     bRoverDirty: Boolean;
  195.  
  196.     { Kin's Madness }
  197.     Document: Variant;
  198.  
  199.     //Syntax: Variant;
  200.     procedure ResizeRoverToolbar(bLargeView : Boolean);
  201.     procedure RefreshDocumentWeight;
  202.     procedure WMMOVE(var Message: TWMMOVE); message WM_MOVE;
  203.     procedure WMSIZE(var Message: TWMSIZE); message WM_SIZE;
  204.  
  205.     procedure MacroMenuClick(Sender : TObject);
  206.     procedure SetupMacroMenu;
  207.  
  208.     function GetSelText: String;
  209.     procedure SetSelText(sText: String);
  210.     function GetDocText: String;
  211.     procedure SetDocText(sText: String);
  212.     function GetDocHead: String;
  213.     procedure SetDocHead(sText: String);
  214.  
  215.     procedure OpenHDXFile(sFileName: String);
  216.  
  217.     function GetPreviewFileName: String;
  218.  
  219.     function CheckDirty: Boolean;
  220.  
  221.     //Right Click on Main Edit View
  222.     procedure MainViewRightClick(X, Y: Integer);
  223.     procedure DocEditTag;
  224.     procedure ClearCurrentElement;
  225.  
  226.     { Spell Checker }
  227.     procedure CorrectWord(Sender: TObject);
  228.  
  229.     //function FileName: String;
  230.     procedure SearchAndReplace(bFindOnly, bReplaceAll: Boolean; sSearchText,sReplaceText: String; bCase, bMatch: Boolean; Sender: Tobject);
  231.     procedure InsertImage;
  232.     procedure HideRover;
  233.     //procedure RecentFilesItemClick(Sender: TObject); {Hint}
  234.     //procedure SetChildNum(I: Integer); {Hint}
  235.     function ParseForFont(sText: String): THTMLFont;
  236.     procedure AddToSelText(sText: String);
  237.     procedure KillTmpFile;
  238.     //function CleanSaveAsName(sName, sDefExt: String): String; {Hint}
  239.     //procedure AddToRecent;
  240.     procedure HideToolbarShit(bOnlySelectionChanged : Boolean);
  241.     function  GetDocLength: Integer;
  242.     procedure AutoSave;
  243.     procedure PasteFromClipboard(Key : word);
  244.     procedure CopyToClipboard(key : word);
  245.     procedure DisplayFileDialog(sFilter, sInitialDir : String; var Dispatched : WordBool; var Name : WideString; var Accepted : WordBool);
  246.     procedure DisplayGutterPopup(X, Y : Integer);
  247.     function  LoadDocumentServer(bFailedOnce : Boolean) : Boolean;
  248.   protected
  249.       { Protected declarations }
  250.  
  251.   public
  252.     { Public declarations }
  253.     //MyPointer: TfrmDoc;
  254.     //Kin's replacements
  255.     procedure DocQuickColor(sColor : String);
  256.     function GenerateTable(sTabledata : String) : String;
  257.     procedure BuildFontTag(tmpFont: THTMLFont; var sBegin, sEnd: String);
  258.  
  259.     function GetNextWordPos(iPos : Integer) : Integer;
  260.     function GetPrevWordPos(iPos : Integer) : Integer;
  261.     function GetNextLinePos(iPos : Integer) : Integer;
  262.     function GetPrevLinePos(iPos : Integer) : Integer;
  263.     procedure ReplaceText(iStartPos, iLength : Integer; sReplaceText : String);
  264.     procedure AddText(sText, sEnd: String; bSkipRemoval: Boolean); virtual;
  265.     { Form Focus }
  266.     procedure GotFocus; virtual;
  267.     function GetTagAtScreenCoords(tPos: TPoint): String;
  268.     function SelStart: LongInt;
  269.     function SelEnd: LongInt;
  270.     function SelLength: LongInt;
  271.     function Find(sString: String; iStart: Integer; bCase: Boolean; bWholeWord: Boolean): LongInt;
  272.     procedure InsertText(sText: String; iPos: LongInt);
  273.     procedure SelectAll;
  274.     procedure SetCursorPos(iPos: Integer);
  275.     procedure SetSelection(iStart, iLength: Integer);
  276.  
  277.     function GetWordAtPos(iPos: Integer; var iStart, iEnd: Integer): String;
  278.     function GetNextTextBlock(var iStart: Integer): String;
  279.     function GetNextTag(var iStart: Integer): String;
  280.     function CreateTagsDropText(Source: TObject; sHighlighted : String):string;
  281.     { EditView Shite }
  282.     procedure UpdateTagColors;
  283.     procedure UpdateSyntax;
  284.     {colours}
  285.     procedure LoadSyntaxColours(Document : THTMLEditView);
  286.  
  287.     { Document Parsing Fucntions }
  288.     function GetTextRange(iStart, iLength: Integer): String;
  289.     //Get Head positions
  290.     function FindDocHead(var iStart, iEnd: Integer): Boolean;
  291.     procedure FindMatchingCharacter(iPosition : Integer);
  292.     //Return HTML Element
  293.     function GetElementAt(iPosition: Integer; var iStart: Integer; var sElement: String): Variant;
  294.     function SniffElements(sResult: TStringList; bIncludePositions: Boolean): Integer;
  295.  
  296.     function PublishFields : Integer;
  297.     procedure PublishAutoFields;
  298.     procedure InsertPublishField;
  299.  
  300.     //Style Sheets
  301.     procedure DocStyle(sStyleTag : String);
  302.  
  303.     { Form Main menu item shit }
  304.     procedure Save; virtual;
  305.     procedure SaveAs; virtual;
  306.     function DocSaveAsRemote: Boolean;
  307.  
  308.     //procedure DocExportToText;
  309.     procedure StripTags;
  310.     procedure DocReplace;
  311.     procedure InsertLink(Mode: modeInsert);
  312.     procedure InsertLine;
  313.     procedure InsertTable;
  314.     function CanUndo: Boolean;
  315.     function GetUndoCount : Integer;
  316.     function GetNextUndoText : String;
  317.     function GetUndoItemText(Index : Integer) : String;
  318.     procedure UndoTo(Index : Integer);
  319.     function GetNextRedoText : String;
  320.     function CanRedo: Boolean;
  321.     function GetRedoCount : Integer;
  322.     function GetRedoItemText(Index : Integer) : String;
  323.     procedure RedoTo(Index : Integer);
  324.  
  325.     procedure UpdateBodyTag(sBodyTag: String); virtual;
  326.     function GetBodyTag : String;
  327.     procedure DocInsert(Mode: modeInsert);
  328.     procedure DocCut;
  329.     procedure DocCopy;
  330.     procedure DocPaste;
  331.     procedure DocPasteTable;
  332.     procedure DocPasteLeftAligned;
  333.     procedure DocUndo;
  334.     procedure DocRedo;
  335.     procedure DocDelete;
  336.     procedure DocFind;
  337.     procedure DocFindF3;
  338.     procedure DocFont(bFromRightClick : Boolean);
  339.     procedure DocBold;
  340.     procedure DocBody;
  341.     procedure DocItalic;
  342.     procedure DocUnderline;
  343.     procedure DocPara;
  344.     procedure DocBreak;
  345.     procedure DocNOBR;
  346.     procedure DocCenter;
  347.     procedure DocPrintSetup;
  348.     procedure DocPrint;
  349.     procedure DocBigFirst;
  350.     procedure DocPreview;
  351.     function DocPreviewWithBrowser(sBrowser: String): Boolean;
  352.     function DocPreviewWithLastBrowser : Boolean;
  353.     procedure DocHeading(iHeading: Integer);
  354.     procedure OpenDoc(sFileName: String);
  355.     //procedure InternetOpenDoc(sSiteName, sFileName, sRemoteFileName: String);
  356.     procedure InternetOpenDoc(sLocalFile, sRemotePath: String; tInfo: FTP_SITE_INFO);
  357.     procedure OpenTemplate(sFileName: String);
  358.     procedure QuickLink(sFileName: String);
  359.     procedure QuickImage(sFileName: String);
  360.     procedure QuickTable(sTableText: String);
  361.     procedure DocFrameWizard;
  362.     procedure DocFaveLink(sFileName, sDesc: String);
  363.     procedure DocPublish;
  364.     procedure DocPublishToFileOrScreen;
  365.     {-= MrKistic - 19 november 1997 =-}
  366.     {-= new =-}
  367.     function PublishDocumentInAShouseyManner: Integer;
  368.  
  369.     function DocPublishAndSave : Integer;    //silent - used from frmUpload
  370.     procedure InsertList;
  371.     {procedure BullList;
  372.     procedure NumList;}
  373.     procedure DocList;
  374.     procedure DocDefList;
  375.     procedure DocComment;
  376.     procedure DocDate;
  377.     procedure DocHotdogVersion;
  378.     procedure DocCurrentFilename;
  379.     procedure DocWindowsVersion;
  380.     procedure DocUserName;
  381.     procedure DocCompanyName;
  382.     procedure DocEmbeded;
  383.     procedure DocProperties;
  384.     procedure DocMeta;
  385.     procedure DocColor; //Can't do this yet - kin
  386.     procedure DocInsertTarget;
  387.  
  388.     function DocConvertExtChar: Integer;
  389.     function DocConvertTagCase(bPublishing, bUppercase : Boolean) : Integer;
  390.     procedure DocConvertCase(bUpperCase : Boolean);
  391.     function ReplaceAll(sFind, sReplace: String): Integer;
  392.     function DocConvertSlash: Integer;
  393.     function DocConvertCR(bSelText : Boolean) : Integer;
  394.     procedure PartnerButton;
  395.  
  396.     { Spell Checker }
  397.     function GetNextSpellWord: String;
  398.     procedure SelectSpellWord;
  399.     procedure CorrectSpellWord(sWord: String);
  400.     procedure CheckSpelling;
  401.  
  402.     procedure ShowThesaurus;
  403.     //procedure BeginSpelling;
  404.  
  405.     { Form Elements }
  406.     procedure FormCheckBox;
  407.     procedure FormTextBox;
  408.     procedure FormHidden;
  409.     procedure FormPassword;
  410.     procedure FormRadio;
  411.     procedure FormReset;
  412.     procedure FormSubmit;
  413.     procedure FormTextArea;
  414.     procedure FormList;
  415.     procedure FormImage;
  416.     procedure FormWizard;
  417.  
  418.     procedure DocRelToAbs;
  419.     procedure DocAbsToRel;
  420.  
  421.     procedure SetFileFormat(DocType: DocEOLType);
  422.     procedure ToggleFileFormat;
  423.     procedure Reparse;
  424.     function  GetBookmarks : String;
  425.     procedure GotoBookmark(sBookmark : String);
  426.     function  GetCurrentLine : Integer;
  427.     function  GetLinePosition(iLine : Integer) : Integer;
  428.     function  GetNextElementPos(iType : Integer; iStart: Integer): Integer;
  429.     function  GetPreviousElementPos(iType : Integer; iStart : Integer) : Integer;
  430.  
  431.     function GetDocumentStorageHandle: HGlobal;
  432.     procedure LoadStorageMemory(hMem: HGlobal);
  433.     procedure HideSyntaxPicker;
  434.   published                           
  435.       { Published declarations }
  436.     { example property Digits   : byte read FDigits write setDigits; }
  437.     //property ChildNumber: Integer read iChildNum write SetChildNum;
  438.     property FileName: String read sDocFileName write sDocFileName;
  439.     property PreviewFileName: String read GetPreviewFileName;
  440.     property Dirty: Boolean read CheckDirty;
  441.     //Kin's replacements
  442.     property SelText: String read GetSelText write SetSelText;
  443.     property Text: String read GetDocText write SetDocText;
  444.     property DocLength: Integer read GetDocLength;
  445.     { Other properties }
  446.     property Head: String read GetDocHead write SetDocHead;
  447.     //Check to see if initialisation went OK
  448.     property Setup: Boolean read bSetup;
  449.     property RoverDirty: Boolean read bRoverDirty write bRoverDirty;
  450.     { Remote Properties }
  451.     property InternetFile: Boolean read bInternet write bInternet default False;
  452.     property InternetFileName: String read sInternetFileName write sInternetFileName;
  453.   end;
  454.  
  455. var
  456.   frmDoc: TfrmDoc;
  457.   iBookMarkWidth : Integer;
  458.   dlgFind : TFindDialog;
  459. const
  460.     INS_NUM_LIST: Integer = 0;
  461.     INS_B_LIST: Integer = 1;
  462.     INS_LINE: Integer = 2;
  463.     INS_FORM: Integer = 3;
  464.     INS_TABLE: Integer = 4;
  465.     INS_LINK: Integer = 5;
  466.     INS_TARGET: Integer = 6;
  467.     INS_OBJECT_CONTAINER: Integer = 7;
  468.     INS_IMAGE: Integer = 8;
  469.     INS_IMG_MAP: Integer = 9;
  470.     INS_FRAMES: Integer = 10;
  471.     INS_MARQUEE: Integer = 11;
  472.  
  473.     FMT_FONT: Integer = 0;
  474.     FMT_FONT_COLOUR: Integer = 1;
  475.     FMT_BIG_FIRST: Integer = 2;
  476.     FMT_SUPER_SCRIPT: Integer = 3;
  477.     FMT_SUB_SCRIPT: Integer = 4;
  478.     FMT_STRIKETHRU: Integer = 5;
  479.     FMT_BACKGROUND: Integer = 6;
  480.     FMT_INDENT_IN: Integer = 7;
  481.     FMT_INDENT_OUT: Integer = 8;
  482.     FMT_ALIGN_LEFT: Integer = 9;
  483.     FMT_ALIGN_CENTER: Integer = 10;
  484.     FMT_ALIGN_RIGHT: Integer = 11;
  485.     FMT_SYNTAX_CHECK: Integer = 12;
  486.     FMT_SPELL_CHECK: Integer = 13;
  487.  
  488. {-= MrKistic - 7 October 1997 =-}
  489. {-= Inline Rover Stuff =-}
  490.     SPLIT_WEB_HEIGHT: Integer = 24;
  491.     SPLIT_ROVER_HEIGHT: Integer = 10;
  492. //Gutter Schtuff
  493.     LINE_GUTTER_SIZE = 920;
  494.     NO_LINE_GUTTER_SIZE = 450;
  495.     NO_GUTTER_SIZE  = 100;
  496. implementation
  497.  
  498. uses fMain, fMainRover, uRover, fImage, uMDI, fLink, fInsRule, comObj,
  499.      UPTShellControls, fDlg, fFontDlg, table_wizard, frame_wizard, Clipbrd,
  500.      fNewOptions, {WinShell,} IniFiles, SSCE, fQuickList, uReadHDX,
  501.      uFindReplace, Checkfrm, ftxtfrm, hidefrm, passfrm, radiofrm, resetfrm,
  502.      submitfrm, TextArea, imagefrm, listfrm, uTags, uProject,
  503.      fComment, frmDocProp, fSpellDlg, fformWiz, fUpload, fIntLink, {fImagePrev,}
  504.      fEmbed, ThumbNailButton, fPublishField, uPublish,fGrabPage, fDirList, uFileDialogs,
  505.      FileCtrl, oledrop, fDefList, fMeta, ShellAPI, fThesaurus, {iv,}
  506.      fRemoteDlg, fPublishMsg, fEditMacro, fImageLab, uMainForm, uDocSize;
  507.  
  508.  
  509. {$R *.DFM}
  510.  
  511. procedure TfrmDoc.DocStyle(sStyleTag : String);
  512. begin
  513.     AddText(tOptions.TagCase(sStyleTag) + SelText, tOptions.TagCase(sStyleTag), False);
  514. end;
  515.  
  516. procedure TfrmDoc.FormClose(Sender: TObject; var Action: TCloseAction);
  517. var
  518.     wrdResult: Word;
  519. begin
  520.     Action := caFree;
  521.     try
  522.         if bSetup then
  523.         begin
  524.             wrdResult := CheckSave;
  525.             if (tOptions.ReopenFiles) and (tOptions.RecordingFiles) and (sDocFileName <> '') and (not(InternetFile)) then
  526.                tOptions.FilesToReopen := tOptions.FilesToReopen + sDocFileName + ',';
  527.             if wrdResult <> mrCancel then
  528.             begin
  529.                 try
  530.                    bSetup := False;
  531.                    //-- Sav --  Get rid of any temp preview files lying around.
  532.                    DeleteFile(PChar(GetPreviewFileName));
  533.                    if bInternet then
  534.                        DeleteFile(sDocFileName);
  535.                    KillTmpFile;
  536.                    HideRover;
  537.  
  538.                    MainForm.DirtyBird(False);
  539.                    //MainForm.HideShit;
  540.                    Rover.ClearView;
  541.                    if Assigned(MainForm.propSheet) then
  542.                        MainForm.propSheet.Selection := Nil;
  543.                    {if Self.ClassName = 'TfrmDocRover' then
  544.                    begin
  545.                         (Self as TfrmDocRover).FreeRover;
  546.                         Application.ProcessMessages;
  547.                    end;}
  548.                    MDI.RemoveMDIChild(Self);
  549.                    try
  550.                        if Assigned(MainForm.tpnlProjects) then
  551.                            tProject.DocumentClosed(sDocFileName);
  552.                    except
  553.                    end;
  554.                    HotDogSound(INI_SOUNDS_CLOSE);
  555.                    if (MainForm is TfrmMainRover) then
  556.                         (MainForm as TfrmMainRover).CheckDocumentState(True);
  557.                    //Document.SetSyntaxManager(Null);
  558.                 finally
  559.                     Action := caFree;
  560.                 end;
  561.             end
  562.             else
  563.                 Action := caNone;
  564.         end
  565.         else
  566.         begin
  567.             try
  568.                wrdResult := mrOK;
  569.                if Assigned(MainForm.propSheet) then
  570.                    MainForm.propSheet.Selection := Nil;
  571.                MDI.RemoveMDIChild(Self);
  572.                try
  573.                    if Assigned(MainForm.tpnlProjects) then
  574.                        tProject.DocumentClosed(sDocFileName);
  575.                except
  576.                end;
  577.             finally
  578.                 Action := caFree;
  579.             end;
  580.         end;
  581.         ModalResult := wrdResult;
  582.     except
  583.     end;
  584. end;
  585.  
  586. procedure TfrmDoc.OpenDoc(sFileName: String);
  587. begin
  588.     if ExtractFileExt(sFileName) = '.hde' then
  589.         OpenHDXFile(sFileName)
  590.     else
  591.         if FileExists(sFileName) then
  592.         begin
  593.             sDocFileName := sFileName;
  594.             sBackupFileName := GetTempFile(PChar(GetTempDirectory));
  595.             Document.LoadFromFile(sFileName);
  596.             SetFileFormat(Document.EOLType);
  597.  
  598.             rtfDoc.ScrollToTop; //Uncommented by Sav 01-09-97
  599.  
  600.             if Find('<BODY', 0, False, False) > -1 then
  601.             begin
  602.                 DocBody;
  603.                 //SetCursorPos(Find('<BODY', 0, False, False) + 7);
  604.             end; //Sav 01-09-97 - find the beginning of the body instead of the end.
  605.  
  606.             {if DEBUG_FLAG then
  607.                 ShowMessage('Document succesfully loaded');}
  608.  
  609.             if tOptions.BackupFiles then
  610.                 Document.SaveToFile(sBackupFileName);
  611.  
  612.             Caption := sFileName;
  613.  
  614.             //add tab
  615.             MDI.AddDocumentTab(ExtractFileName(sFileName), Self);
  616.             //tProject.AddSnifferDocument(sFileName);
  617.  
  618.             bDocDirty := False;
  619.             bRoverDirty := True;
  620.             AddToMRU(sFileName);
  621.             HideToolbarShit(False);
  622.         end;
  623. end;
  624.  
  625. procedure TfrmDoc.InternetOpenDoc(sLocalFile, sRemotePath: String; tInfo: FTP_SITE_INFO);
  626. {-= InternetOpenDoc: If parameter is valid filename, open this file =-}
  627. {-= sLocalFile: Local copy of remote file                             =-}
  628. {-= sRemotePath: full path to remote file on server                 =-}
  629. {-= tInfo: contains Internet Server Information                        =-}
  630. begin
  631.     try
  632.         if FileExists(sLocalFile) then
  633.         begin
  634.             tInternetServer := tInfo;
  635.             InternetFile := True;
  636.             //-- Sav -- Leave sDocFilename blank so that references are absolute.
  637.             //sDocFileName := sLocalFile;
  638.             sInternetFileName := sRemotePath;
  639.             sBackupFileName := GetTempFile(PChar(GetTempDirectory));
  640.             Document.LoadFromFile(sLocalFile);
  641.             //Document.LoadFromFile(sDocFileName);
  642.             SetFileFormat(Document.EOLType);
  643.  
  644.             rtfDoc.ScrollToTop;
  645.  
  646.             if Find('<BODY', 0, False, False) > -1 then
  647.                 SetCursorPos(Find('<BODY', 0, False, False) + 7);
  648.  
  649.             if tOptions.BackupFiles then
  650.                 Document.SaveToFile(sBackupFileName);
  651.  
  652.             Caption := sInternetFileName;
  653.  
  654.             {-= add document tab =-}
  655.             MDI.AddDocumentTab(sInternetFileName, Self);
  656.             //tProject.AddSnifferDocument(sInternetFileName);
  657.  
  658.             bDocDirty := False;
  659.             bRoverDirty := True;
  660.             HideToolbarShit(False);
  661.  
  662.         end;
  663.     except
  664.         //nada
  665.     end;
  666. end;
  667.  
  668. procedure TfrmDoc.OpenHDXFile(sFileName: String);
  669. var
  670.     sHTMLPath, sHTMLFile: String;
  671. begin
  672.     if FileExists(sFileName) then
  673.     begin
  674.         {if DEBUG_FLAG then
  675.             ShowMessage('Attempting to open document: ' + sFileName);}
  676.  
  677.         Status('Converting HotDog Express file...');
  678.         sHTMLPath := ExtractFileDir(HotDogExpressPath);
  679.         sHTMLPath := FilePath(sHTMLPath, 'HTMLFiles');
  680.         sHTMLFile := ExtractFileName(sFileName);
  681.         sHTMLFile := StripFileExtension(sHTMLFile) + '.html';
  682.         sHTMLFile := FilePath(sHTMLPath, sHTMLFile);
  683.         WriteWholeFile(sHTMLFile, ReadHDXFile(sFileName));
  684.  
  685.         if FileExists(sHTMLFile) then
  686.         begin
  687.             sDocFileName := sHTMLFile;
  688.             sBackupFileName := GetTempFile(PChar(GetTempDirectory));
  689.             Document.LoadFromFile(sHTMLFile);
  690.             SetFileFormat(Document.EOLType);
  691.             //rtfDoc.ScrollToTop;
  692.             if Find('</BODY>', 0, False, False) > -1 then
  693.             begin
  694.                 SetCursorPos(Find('</BODY>', 0, False, False) - 2);
  695.             end;
  696.         end
  697.         else
  698.             MessageDlg('An error has occurred while converting your HotDog Express file.', mtError, [mbOK], 0);
  699.  
  700.         {if DEBUG_FLAG then
  701.             ShowMessage('Document succesfully loaded');}
  702.  
  703.         if tOptions.BackupFiles then
  704.             Document.SaveToFile(sBackupFileName);
  705.  
  706.         bDocDirty := False;
  707.         bRoverDirty := True;
  708.         Caption := sHTMLFile;
  709.  
  710.         //add tab
  711.         MDI.AddDocumentTab(ExtractFileName(sHTMLFile), Self);
  712.         //tProject.AddSnifferDocument(sFileName);
  713.  
  714.         AddToMRU(sFileName);
  715.         HideToolbarShit(False);
  716.         Status('');
  717.     end;
  718. end;
  719.  
  720. procedure TfrmDoc.OpenTemplate(sFileName: String);
  721. var
  722.     sTempFile: String;
  723.     iPos: Integer;
  724. begin
  725.     try
  726.     begin
  727.         if FileExists(sFileName) then
  728.         begin
  729.             Document.LoadFromFile(sFileName);
  730.             SetFileFormat(Document.EOLType);
  731.             PublishAutoFields;
  732.             //rtfDoc.ScrollToTop;
  733.         end
  734.         else
  735.         begin
  736.             sTempFile := GetTempFile(PChar(GetTempDirectory));
  737.             try
  738.                 Document.Text := DEFAULT_DOCUMENT;
  739.                 SetFileFormat(Document.EOLType);
  740.                 //rtfDoc.ScrollToTop;
  741.             finally
  742.                 DeleteFile(sTempFile);
  743.             end;
  744.         end;
  745.         bDocDirty := False;
  746.         iPos := Find('</BODY>', 0, False, False);
  747.         if iPos > -1 then
  748.         begin
  749.             SetCursorPos(iPos - 2);
  750.         end;
  751.         sBackupFileName := GetTempFile(PChar(GetTempDirectory));
  752.         Caption := 'Untitled';
  753.  
  754.         //Application.ProcessMessages;
  755.         //add tab
  756.         MDI.AddDocumentTab(Caption, Self);
  757.         //tProject.AddSnifferDocument(Caption);
  758.         HideToolbarShit(False);
  759.         //Don't want to be able to undo the stuff we just put in.
  760.         Document.UndoManager.Reset;
  761.         GotFocus;
  762.     end
  763.     except
  764.     end;
  765. end;
  766.  
  767. procedure TfrmDoc.SaveAs;
  768. var
  769.     tDlgSave: TFileDialog;
  770.     sOldFileName: String;
  771. begin
  772.     //Checkit
  773.     tDlgSave := TFileDialog.Create(Self);
  774.     try
  775.     begin
  776.         KillTmpFile;
  777.         //tDlgSave.UseWinDialog := not(tOptions.UseCustomFileDialog);
  778.         tDlgSave.InitialDir := tOptions.DocumentDirectory;
  779.         tDlgSave.DefaultExt := tOptions.DefaultDocExtension;
  780.         tDlgSave.WinOptions := [ofOverwritePrompt, ofHideReadOnly];
  781.         tDlgSave.OpenFile := False;
  782.         tDlgSave.CustomOptions := [ptofOverwritePrompt, ptofHideReadOnly];
  783.         tDlgSave.Filter := SAVE_FILTER_;
  784.         if tDlgSave.Execute then
  785.         begin
  786.  
  787.             //if bInternet then
  788.             //     DeleteFile(sDocFileName);
  789.             InternetFile := False;
  790.  
  791.             tOptions.LastHTMLDir := ExtractFilePath(tDlgSave.FileName);
  792.             sOldFileName := sDocFileName;
  793.             sDocFileName := tDlgSave.FileName;
  794.  
  795.             Document.SaveToFile(sDocFileName);
  796.             if tOptions.BackupFiles then
  797.                 Document.SaveToFile(sBackupFileName);
  798.             bDocDirty := False;
  799.             Caption := sDocFileName;
  800.             //MainForm.Draw(True);
  801.             //change tab
  802.             MDI.UpdateTabName(Self, ExtractFileName(sDocFileName));
  803.             //tProject.UpdateSniffer(MDI.MDIChildIndex(Self), sDocFileName);
  804.  
  805.             AddToMRU(sDocFileName);
  806.             if Assigned(MainForm.tpnlProjects) then
  807.                 tProject.DocumentSavedAs(sOldFileName, tDlgSave.Filename);
  808.             if tOptions.SaveBrowserRefresh then
  809.                     DocPreviewWithLastBrowser;
  810.             HideToolbarShit(False);
  811.             if (Rover.SaveRefresh) and (MainForm is TfrmMainRover) then
  812.                 (MainForm as TfrmMainRover).UpdateRover;
  813.             //MainForm.RefreshDocumentWeight;
  814.         end;
  815.     end
  816.     finally
  817.         tDlgSave.Free;
  818.     end;
  819. end;
  820.  
  821. procedure TfrmDoc.Save;
  822. var
  823.     sBackup: String;
  824.     tServer: tWWWServerType;
  825. begin
  826.     try
  827.         if InternetFile then
  828.         begin
  829.             if not(Assigned(frmUpload)) then
  830.             begin
  831.                try
  832.                  //-- Sav -- SDocFilename is now '' so make a file to upload.
  833.                  sDocFileName := FilePath(GetTempDirectory,ExtractFileName(ReplaceString(sInternetFileName, '/', '\')));
  834.                  Document.SaveToFile(sDocFileName);
  835.                  try
  836.                     Screen.Cursor := crHourglass;
  837.                     Application.CreateForm(TfrmUpload, frmUpload);
  838.                  finally
  839.                     Screen.Cursor := crDefault;
  840.                  end;
  841.                  frmUpload.Caption := 'Saving Remote Document...';
  842.                  frmUpload.IsDocument := True;
  843.                  frmUpload.DocFileName := sDocFileName;
  844.                  frmUpload.InternetFileName := sInternetFileName;
  845.                  tServer.sAddress := tInternetServer.sAddress;
  846.                  tServer.sDirectory := tInternetServer.sDirectory;
  847.                  tServer.sUserName := tInternetServer.sUserName;
  848.                  tServer.sPassword := tInternetServer.sPassword;
  849.                  tServer.iPort := tInternetServer.iPort;
  850.                  tServer.iTimeOut := tInternetServer.iTimeOut;
  851.                  frmUpload.TimeOut := (tInternetServer.iTimeOut div 1000);
  852.                  frmUpload.tServer := tServer;
  853.                  frmUpload.FormStyle := fsStayOnTop;
  854.                  frmUpload.Show;
  855.  
  856.                  repeat
  857.                      Application.ProcessMessages;
  858.                  until frmUpload.DoneConnect;
  859.  
  860.                  if frmUpload.Connected then
  861.                  begin
  862.                    if tOptions.BackupFiles then
  863.                    begin
  864.                        sBackup := RemoteFilePath(ExtractRemoteFilePath(sInternetFileName),
  865.                                        ExtractRemoteFileName(sInternetFileName) + '.bak');
  866.                        frmUpload.FTPRenameFile(sInternetFilename, sBackup);
  867.                    end;
  868.                    if frmUpload.Go then
  869.                        bDocDirty := False;
  870.  
  871.                    if tOptions.SaveBrowserRefresh then
  872.                         DocPreviewWithLastBrowser;
  873.                    if (Rover.SaveRefresh) and (MainForm is TfrmMainRover) then
  874.                        (MainForm as TfrmMainRover).UpdateRover;
  875.                    HideToolbarShit(False);
  876.                  end;
  877.                finally
  878.                  frmUpload.Close;
  879.                  frmUpload.Free;
  880.                  frmUpload := Nil;
  881.                end;
  882.             end;
  883.         end
  884.         else
  885.         begin
  886.             if Length(sDocFileName) > 0 then
  887.             begin
  888.                 //sBackupFileName := FilePath(ExtractFileDir(sDocFileName),  '~hd$' + ExtractFileName(sDocFileName));
  889.                 //sBackup := FilePath(ExtractFileDir(sDocFileName),  'Backup of ' + ExtractFileName(sDocFileName));
  890.                 sBackup := FilePath(ExtractFileDir(sDocFileName),  StripFileExtension(ExtractFileName(sDocFileName))) + '.' + tOptions.BackupExt;
  891.                 if tOptions.BackupFiles then
  892.                 begin
  893.                     CopyFile(PChar(sBackupFileName), PChar(sBackup), False);
  894.                     Document.SaveToFile(sBackupFileName);
  895.                 end;
  896.                 Document.SaveToFile(sDocFileName);
  897.                 bDocDirty := False;
  898.                 if tOptions.SaveBrowserRefresh then
  899.                     DocPreviewWithLastBrowser;
  900.                 if (Rover.SaveRefresh) and (MainForm is TfrmMainRover) then
  901.                     (MainForm as TfrmMainRover).UpdateRover;
  902.                 HideToolbarShit(False);
  903.                 if Assigned(MainForm.tpnlProjects) then
  904.                     tProject.DocumentSaved(sDocFileName);
  905.  
  906.                 //MainForm.RefreshDocumentWeight;
  907.             end
  908.             else
  909.             begin
  910.                 SaveAs;
  911.             end;
  912.         end;
  913.     except
  914.     end;
  915. end;
  916.  
  917. function TfrmDoc.CheckSave: Word;
  918. { Function checks if document is dirty, if so asks to save changes. }
  919. { If yes, saves document. Return value one of [mrYes, mrNo, mrCancel], }
  920. { corresponding to users choice in dialog. }
  921. var
  922.     wrdReturnValue: Word;
  923.     sCaption: String;
  924.     sFileName: String;
  925. begin
  926.     wrdReturnValue := mrYes;
  927.     if bDocDirty then
  928.     begin
  929.         if Length(sDocFileName) = 0 then
  930.            sFileName := 'Untitled'
  931.         else
  932.            sFileName := sDocFileName;
  933.         if bInternet then
  934.            sCaption := 'Save changes to ' + ExtractFileName(InternetFileName) + '?'
  935.         else
  936.            sCaption := 'Save changes to ' + ExtractFileName(sFileName) + '?';
  937.         wrdReturnValue := MessageDlg(sCaption, mtConfirmation, [mbYes, mbNo, mbCancel], 0);
  938.         if wrdReturnValue = mrYes then
  939.             Save;
  940.     end;
  941.     Result := wrdReturnValue;
  942. end;
  943.  
  944. function  TfrmDoc.LoadDocumentServer(bFailedOnce : Boolean) : Boolean;
  945. var
  946.     sRegFilename : String;
  947.     OleSysError: EOleSysError;
  948.     OleException: EOleException;
  949. begin
  950.     result := True;
  951.     try
  952.         Document := CreateOLEObject('Sausage.HTMLTextDocument.2');
  953.     except
  954.         on e: Exception do
  955.         begin
  956.             begin
  957.                 if e is EOleException then
  958.                 begin
  959.                     OleException := (e as EOleException);
  960.                     MessageDlg(OleException.Message, mtError, [mbOK], 0);
  961.                 end
  962.                 else if e is EOleSysError then
  963.                 begin
  964.                     OleSysError := (e as EOleSysError);
  965.                     if DWord(OleSysError.ErrorCode) = CO_E_CLASSSTRING then
  966.                     begin
  967.                         if bFailedOnce then
  968.                             MessageDlg('Invalid class string : The file "HTMLDocumentSvr2.dll" has not been registered correctly.', mtError, [mbOK], 0)
  969.                         else
  970.                         begin
  971.                             RegisterFiles;
  972.                             result := LoadDocumentServer(True);
  973.                             Application.ProcessMessages;
  974.                             Exit;
  975.                         end;
  976.                     end
  977.                     else if DWord(OleSysError.ErrorCode)= REGDB_E_CLASSNOTREG then
  978.                     begin
  979.                         if bFailedOnce then
  980.                             MessageDlg('Class not registered : The file "HTMLDocumentSvr2.dll" has not been registered correctly.', mtError, [mbOK], 0)
  981.                         else
  982.                         begin
  983.                             RegisterFiles;
  984.                             Application.ProcessMessages;
  985.                             result := LoadDocumentServer(True);
  986.                             Exit;
  987.                         end;
  988.                     end
  989.                     else if OleSysError.ErrorCode = ERROR_DLL_NOT_FOUND then
  990.                     begin
  991.                         MessageDlg('DLL not found : The file "HTMLDocumentSvr2.dll" has been registered but could not be loaded correctly.',
  992.                                 mtError, [mbOK], 0);
  993.                     end
  994.                     else if OleSysError.ErrorCode = -2147023739 then
  995.                     begin
  996.                         MessageDlg('DLL not found : The file "HTMLDocumentSvr2.dll" has been registered but could not be loaded correctly.',
  997.                                 mtError, [mbOK], 0);
  998.                     end
  999.                     else
  1000.                         MessageDlg(OleSysError.Message, mtError, [mbOK], 0);
  1001.                 end
  1002.                 else
  1003.                     MessageDlg(e.message, mtError, [mbOK], 0);
  1004.             end;
  1005.             Result := False;
  1006.         end;
  1007.     end;
  1008. end;
  1009.  
  1010. procedure TfrmDoc.FormCreate(Sender: TObject);
  1011. var
  1012.     c: Integer;
  1013.     bContinue: Boolean;
  1014. begin
  1015.     bContinue := True;
  1016.     bSetup := False;
  1017.     bActive := False;
  1018.     bFirstLoaded := True;
  1019.     iBookMarkWidth := (rtfDoc.BookmarkWidth * 4);
  1020.     c := Screen.Cursor;
  1021.     try
  1022.         Screen.Cursor := crHourglass;
  1023.         if rtfDoc <> nil then
  1024.         begin
  1025.             rtfDoc.SetBounds(0, 0, ClientWidth, (ClientHeight - panButtons.Height));
  1026.             rtfDoc.HideSelection := False;
  1027.         end;
  1028.  
  1029.         bContinue := LoadDocumentServer(False);
  1030.         if bContinue then
  1031.         begin
  1032.             btnShowButtons.glyph.LoadFromResourceName(hInstance, 'bmpDocToolbarCollapse');
  1033.             Document.SetSyntaxManager(SyntaxManager);
  1034.             rtfDoc.Document := IDispatch(Document);
  1035.             //rtfDoc.SyntaxHighlight := True;
  1036.             rtfDoc.HighLightStyle := HTMLEDITVIEW_SYNTAX;
  1037.             rtfDoc.AutoConvert := False;
  1038.             if Not(tOptions.EditAutoIndent) then
  1039.                 rtfDoc.AutoIndent := False;
  1040.             //UpdateTagColors;
  1041.             //LoadSyntaxColours(rtfDoc); //22/07/98
  1042.             ClearCurrentElement;
  1043.  
  1044.             sDocFileName := '';
  1045.             bInternet := False;
  1046.             iLastFind := 0;
  1047.             iReplaceCount := 0;
  1048.             iUntitledCount := 0;
  1049.             //rtfDoc.Clear;
  1050.  
  1051.             try
  1052.                 SetDisplay;
  1053.             except
  1054.             end;
  1055.             //iLastRoverHeight := ctlRover.Height;
  1056.  
  1057.             rtfDoc.DisplayAll := tOptions.EditPara;
  1058.             rtfDoc.WordWrap := tOptions.EditWordWrap;
  1059.             rtfDoc.MouseSelectionEnable := True;
  1060.             rtfDoc.KeySelectionEnable := True;
  1061.             rtfDoc.CollapseBlockEnable := True;
  1062.             if tOptions.HTMLSyntax = True then
  1063.                rtfDoc.HighLightStyle := HTMLEDITVIEW_SYNTAX
  1064.             else
  1065.             begin
  1066.                If tOptions.HTMLTagColor = True then
  1067.                   rtfDoc.HighLightStyle := HTMLEDITVIEW_TAGS
  1068.                else
  1069.                   rtfDoc.HighLightStyle := HTMLEDITVIEW_NOTAGSYNTAX;     //kin 190997
  1070.             end;
  1071.  
  1072.             spdSyntax.Down := (rtfDoc.HighlightStyle = HTMLEDITVIEW_SYNTAX);
  1073.             spdTag.Down := (rtfDoc.HighLightStyle = HTMLEDITVIEW_TAGS);
  1074.             spdWordWrap.Down := rtfDoc.WordWrap;
  1075.             spdFields.Down := rtfDoc.DisplayAll;
  1076.             //spdGutter.Down := rtfDoc.ShowLineNumber;
  1077.             if not tOptions.OpenMaxDoc then
  1078.             begin
  1079.                 WindowState := wsNormal;
  1080.             end;
  1081.             ResizeRoverToolbar(tOptions.EditorToolbarLarge);
  1082.             timAutoSave.Enabled := tOptions.AutoSave;
  1083.             timAutoSave.Interval := tOptions.AutoSaveTime * 60000;
  1084.         end;
  1085.     finally
  1086.         //ShowWindow(Handle, SW_HIDE);
  1087.         Screen.Cursor := c;
  1088.         bSetup := bContinue;
  1089.     end;
  1090.  end;
  1091.  
  1092. procedure TfrmDoc.SearchAndReplace(bFindOnly, bReplaceAll: Boolean; sSearchText, sReplaceText: String; bCase, bMatch: Boolean; Sender: Tobject);
  1093. var
  1094.     iFoundPos: Integer;
  1095.     sMsgString: String;
  1096.     wrdCheck: Word;
  1097.     bCancel: Boolean;
  1098. begin
  1099.     if bReplaceAll then
  1100.         dlgReplace.CloseDialog;
  1101.     bCancel := False;
  1102.     iLastFind := min_(iLastFind, Document.Length);
  1103.     iFoundPos := Document.FindString(iLastFind, Document.Length, sSearchText, True, bCase, bMatch);
  1104.     if iFoundPos > -1 then
  1105.     begin
  1106.         rtfDoc.SetSelection(iFoundPos, iFoundPos + Length(sSearchText));
  1107.         rtfDoc.ScrollCaretToView;
  1108.         if not bFindOnly then
  1109.         begin
  1110.             wrdCheck := MessageDlg('Replace?', mtConfirmation, [mbYes, mbNo, mbCancel], 0);
  1111.             if wrdCheck = mrYes then
  1112.             begin
  1113.                 //SelText := sReplaceText;
  1114.                 //rtfDoc.ClearSelection;
  1115.                 //Document.InsertText(sReplaceText, iFoundPos);
  1116.                 SelText := sReplaceText;
  1117.                 Inc(iReplaceCount);
  1118.                 iLastfind := iFoundPos + Length(sReplaceText);
  1119.             end
  1120.             else if wrdCheck = mrNo then
  1121.                 iLastFind := iFoundPos + Length(sSearchText)
  1122.             else if wrdCheck = mrCancel then
  1123.             begin
  1124.                 bCancel := True;
  1125.             end;
  1126.         end
  1127.         else
  1128.             iLastfind := iFoundPos + Length(sSearchText);
  1129.  
  1130.         if (Not bFindOnly) and bReplaceAll and not(bCancel) then
  1131.             SearchAndReplace(bFindOnly, bReplaceAll, sSearchText, sReplaceText, bCase, bMatch, Sender);
  1132.     end
  1133.     else
  1134.     begin
  1135.         if (Sender is TFindDialog) then
  1136.         begin
  1137.             dlgFind.CloseDialog;
  1138.             sMsgString := 'Search string "' + sSearchText + '" not found.';
  1139.         end;
  1140.         if (Sender is TReplaceDialog) then
  1141.         begin
  1142.             dlgReplace.CloseDialog;
  1143.             if iReplaceCount = 0 then
  1144.                 sMsgString := 'Search string "' + sSearchText + '" not found.'
  1145.             else
  1146.                 sMsgString := 'HotDog has made ' + IntToStr(iReplaceCount) + ' replacements.';
  1147.         end;
  1148.         MessageDlg(sMsgString, mtInformation, [mbOk], 0);
  1149.     end;
  1150. end;
  1151.  
  1152. procedure TfrmDoc.dlgFindFind(Sender: TObject);
  1153. begin
  1154.     SearchAndReplace(True, False, dlgFind.FindText, '',
  1155.     ((dlgFind.Options*[frWholeWord]) = [frWholeWord]),
  1156.     ((dlgFind.Options*[frMatchCase]) = [frMatchCase]),
  1157.     Sender);
  1158. end;
  1159.  
  1160. procedure TfrmDoc.DocReplace;
  1161. begin
  1162.     {iLastfind := SelStart;
  1163.     iReplaceCount := 0;
  1164.     dlgReplace.Execute;}
  1165.     //FindReplace.Create(Self);
  1166.     FindReplace.Replace;
  1167. end;
  1168.  
  1169. procedure TfrmDoc.dlgReplaceFind(Sender: TObject);
  1170. begin
  1171.     SearchAndReplace(True, False, dlgReplace.FindText, '',
  1172.     ((dlgReplace.Options*[frWholeWord]) = [frWholeWord]),
  1173.     ((dlgReplace.Options*[frMatchCase]) = [frMatchCase]),
  1174.     Sender);
  1175. end;
  1176.  
  1177. procedure TfrmDoc.dlgReplaceReplace(Sender: TObject);
  1178. begin
  1179.     //SearchAndReplace(bFindOnly, bReplaceAll: Boolean; sSearchText,  sReplaceText: String; bCase, bMatch: Boolean; Sender: Tobject);
  1180.     SearchAndReplace(
  1181.         False,    //bFindOnly
  1182.         ((dlgReplace.Options*[frReplaceAll]) = [frReplaceAll]),    //bReplaceAll
  1183.         dlgReplace.FindText,    //sSearchText
  1184.         dlgReplace.ReplaceText,    //sReplaceText
  1185.         ((dlgReplace.Options*[frWholeWord]) = [frWholeWord]),    //bCase
  1186.         ((dlgReplace.Options*[frMatchCase]) = [frMatchCase]),    //bMatch
  1187.         dlgReplace);
  1188. end;
  1189.  
  1190. procedure TfrmDoc.SelectAll;
  1191. begin
  1192.     rtfDoc.SetSelection(0, Document.Length);
  1193. end;
  1194.  
  1195.  
  1196. procedure TfrmDoc.FormActivate(Sender: TObject);
  1197. begin
  1198.     try
  1199.        if Assigned(MainForm.propSheet) then
  1200.             MainForm.propSheet.Selection := rtfDoc.Selection;
  1201.        if not(csDestroying in ComponentState) and not(bActive) and bSetup then
  1202.        begin
  1203.            //if Rover.DocumentForm <> Self then
  1204.            if MDI.ActiveMDIChild <> Self then
  1205.                    timActivate.Enabled := True;
  1206.        end;
  1207.        MDI.SetActiveTab(MDI.ActiveMDIChild);
  1208.     except
  1209.     end; 
  1210. end;
  1211.  
  1212. procedure TfrmDoc.timActivateTimer(Sender: TObject);
  1213. begin
  1214.     timActivate.Enabled := False;
  1215.     GotFocus;
  1216.     if (MainForm is TfrmMainRover) then
  1217.        (MainForm as TfrmMainRover).PosRefreshRover(PreviewFilename, Text);
  1218. end;
  1219.  
  1220. procedure TfrmDoc.GotFocus;
  1221. begin
  1222.     if not(csDestroying in ComponentState) and not(bCloseAll) and bSetup then
  1223.     begin
  1224.         bActive := True;
  1225.         MainForm.DirtyBird(True);
  1226.         HideToolbarShit(True);
  1227.         if not(MDI.TabChanging) then
  1228.             MDI.SetActiveTab(Self);
  1229.         //tProject.SetSnifferDoc(MDI.MDIChildIndex(Self));
  1230.         SetFocus;
  1231.         bActive := False;
  1232.         if Assigned(MainForm.propSheet) then
  1233.             MainForm.propSheet.Selection := rtfDoc.Selection;
  1234.         if (MainForm is TfrmMainRover) then
  1235.             (MainForm as TfrmMainRover).UpdateRover;
  1236.     end;
  1237. end;
  1238.  
  1239. function EnumFontsProc(var LogFont: TLogFont; var TextMetric: TTextMetric;
  1240.   FontType: Integer; Data: Pointer): Integer; stdcall;
  1241. begin
  1242.     THTMLEditView(Data).EditFont.Charset := LogFont.lfCharSet;
  1243.     //THTMLEditView(Data).EditFont.Height := LogFont.lfHeight;
  1244. end;
  1245.  
  1246. procedure TfrmDoc.SetDisplay;
  1247. var
  1248.   DC: HDC;
  1249. begin
  1250.    try
  1251.     rtfDoc.Enabled := False;
  1252.     try
  1253.        rtfDoc.EditFont.Name := tOptions.ViewFontName;
  1254.        rtfDoc.EditFont.Size := tOptions.ViewFontSize;
  1255.     except
  1256.     end;
  1257.     rtfDoc.FormatBackColor[0] := HTMLToColor(tOptions.ViewBackColour);
  1258.     rtfDoc.BackColor := rtfDoc.FormatBackColor[0];
  1259.     rtfDoc.FormatTextColor[0] := HTMLToColor(tOptions.ViewTextColour);
  1260.     rtfDoc.AutoIndent := tOptions.EditAutoIndent;
  1261.     try
  1262.       DC := GetDC(0);
  1263.       EnumFonts(DC, PChar(rtfDoc.EditFont.Name), @EnumFontsProc, Pointer(rtfDoc));
  1264.       ReleaseDC(0, DC);
  1265.     except
  1266.     end;
  1267.  
  1268.     rtfDoc.DragDropEdit := tOptions.EditDrag;
  1269.     rtfDoc.SmoothRefresh := tOptions.EditSmooth;
  1270.  
  1271.     {code Completion}
  1272.     rtfDoc.CodeCompletion := tOptions.CodeCompletionOn;
  1273.     rtfDoc.CodeCompletionMode := tOptions.CodeCompletionMode;
  1274.     try
  1275.         rtfDoc.CodeCompletionTimeDelay := tOptions.CodeCompletionDelay;
  1276.     except
  1277.         rtfDoc.CodeCompletionTimeDelay := 1000;
  1278.     end;
  1279.  
  1280.  
  1281.     if tOptions.ShowGutter then
  1282.     begin
  1283.         if tOptions.LineGutter then
  1284.         begin
  1285.              rtfDoc.IndentSize := iBookmarkWidth + (tOptions.LineGutterNumber * rtfDoc.GutterFontWidth); //+ rtfDoc.EditFont.Size  //LINE_GUTTER_SIZE;
  1286.              rtfDoc.ShowLineNumber := True;
  1287.         end
  1288.         else
  1289.         begin
  1290.              //rtfDoc.IndentSize := NO_LINE_GUTTER_SIZE;
  1291.              //rtfDoc.IndentSize := rtfDoc.BookmarkWidth * rtfDoc.GutterFontWidth;
  1292.              rtfDoc.IndentSize := iBookmarkWidth + rtfDoc.GutterFontWidth;
  1293.              rtfDoc.ShowLineNumber := False;
  1294.         end;
  1295.         rtfDoc.LeftMarginVisible := True;
  1296.         spdGutter.Down := True;
  1297.     end
  1298.     else
  1299.     begin
  1300.         //rtfDoc.IndentSize := NO_GUTTER_SIZE;
  1301.         rtfDoc.IndentSize := rtfDoc.GutterFontWidth;
  1302.         rtfDoc.ShowLineNumber := False;
  1303.         rtfDoc.LeftMarginVisible := False;
  1304.         spdGutter.Down := False;
  1305.     end;
  1306.     rtfDoc.RightMarginVisible := tOptions.EditRightM;
  1307.     rtfDoc.RightMargin := tOptions.EditRightMSize;
  1308.     if rtfDoc.ColumnMax <> tOptions.EditColMax then
  1309.         rtfDoc.ColumnMax := tOptions.EditColMax;
  1310.     if rtfDoc.TabSize <> tOptions.EditTabSize then
  1311.         rtfDoc.TabSize := tOptions.EditTabSize;
  1312.     rtfDoc.AutoHint := tOptions.HTMLToolTips;
  1313.     rtfDoc.AutoDoc := tOptions.HTMLCoolTips;
  1314.     rtfDoc.AutoCloseBracket := tOptions.HTMLCloseTag;
  1315.     rtfDoc.GutterBitmapVisible := tOptions.ImageGutter;
  1316.  
  1317.     timAutoSave.Enabled := tOptions.AutoSave;
  1318.     timAutoSave.Interval := tOptions.AutoSaveTime * 60000;
  1319.     LoadSyntaxColours(rtfDoc);
  1320.    finally
  1321.     rtfDoc.Enabled := True;
  1322.    end;
  1323. end;
  1324.  
  1325. procedure TfrmDoc.DocInsert(Mode: modeInsert);
  1326. begin
  1327.     case Mode of
  1328.         insImage:
  1329.             InsertImage;
  1330.         insLink:
  1331.             InsertLink(Mode);
  1332.         insEmail:
  1333.             InsertLink(Mode);
  1334.         insFTP:
  1335.             InsertLink(Mode);
  1336.         insNews:
  1337.             InsertLink(Mode);
  1338.         {insTarget:
  1339.             InsertTarget;}
  1340.         insLine:
  1341.             InsertLine;
  1342.         insTable:
  1343.             InsertTable;
  1344.     end;
  1345. end;
  1346.  
  1347. procedure TfrmDoc.InsertImage;
  1348. begin
  1349.     try
  1350.        Screen.Cursor := crHourglass;
  1351.        Application.CreateForm(TfrmImage, frmImage);
  1352.     finally
  1353.        Screen.Cursor := crDefault;
  1354.     end;
  1355.     try
  1356.     begin
  1357.         frmImage.sCurrentText := SelText;
  1358.         frmImage.sDocFileName := sDocFileName;
  1359.         frmImage.ShowModal;
  1360.         if Length(frmImage.sImgText) > 0 then
  1361.             AddText(frmImage.sImgText, '', False);
  1362.     end;
  1363.     finally
  1364.            frmImage.Free;
  1365.     end;
  1366. end;
  1367.  
  1368. function TfrmDoc.PreviewImage(sFilename : String) : String;
  1369. var
  1370.     bResult : Boolean;
  1371. begin
  1372.     try
  1373.        Screen.Cursor := crHourglass;
  1374.        Application.CreateForm(TfrmImagelab, frmImagelab);
  1375.     finally
  1376.        Screen.Cursor := crDefault;
  1377.     end;
  1378.     try
  1379.     begin
  1380.         if sFilename <> '' then
  1381.         begin
  1382.              bResult := frmImageLab.ShowImage('SRC="' + FileToURL(sFilename) + '"', '');
  1383.         end
  1384.         else
  1385.         begin
  1386.             bResult := frmImageLab.ShowImage(SelText,sDocFileName);
  1387.         end;
  1388.         if bResult then
  1389.             frmImagelab.ShowModal;
  1390.         //Get the Public image filename property, so that if a
  1391.         //drag drop called this dialog, it can get the new filename.
  1392.         Result := frmImagelab.sImageFilename;
  1393.     end;
  1394.     finally
  1395.            frmImagelab.Free;
  1396.     end;
  1397. end;
  1398.  
  1399.  
  1400. procedure TfrmDoc.DocComment;
  1401. var
  1402.     tElement: Variant;
  1403.     iStart: Integer;
  1404.     bAutomatic : Boolean;
  1405. begin
  1406.     try
  1407.        Screen.Cursor := crHourglass;
  1408.        Application.CreateForm(TfrmComment, frmComment);
  1409.     finally
  1410.       Screen.Cursor := crDefault;
  1411.     end;
  1412.     try
  1413.         bAutomatic := False;
  1414.         tElement := Document.GetElementAt(SelStart, iStart);
  1415.         if tElement.Type = HTMLSYNTAXELEMENT_COMMENT then
  1416.             frmComment.SetComment(Document.GetTextRange(iStart, iStart + tElement.Length + 1))
  1417.         else
  1418.             frmComment.SetComment(SelText);
  1419.         if frmComment.GetComment = '' then
  1420.             frmComment.ShowModal
  1421.         else
  1422.         begin
  1423.             bAutomatic := True;
  1424.             if not frmComment.ParseComment then
  1425.                 frmComment.CreateComment;
  1426.         end;
  1427.  
  1428.         if (frmComment.ModalResult = mrOK) or (bAutomatic) then
  1429.         begin
  1430.             if tElement.Type = HTMLSYNTAXELEMENT_COMMENT then
  1431.             begin
  1432.                 Document.ReplaceText(iStart, tElement.Length, frmComment.GetComment);
  1433.                 //SelText := frmComment.GetComment;
  1434.             end
  1435.             else
  1436.             begin
  1437.                 if Length(frmComment.GetComment) > 0 then
  1438.                     AddText(frmComment.GetComment, '', False)
  1439.                 else
  1440.                     SelText := frmComment.GetComment;
  1441.             end;
  1442.         end;
  1443.     finally
  1444.            frmComment.Free;
  1445.     end;
  1446. end;
  1447.  
  1448.  
  1449. procedure TfrmDoc.DocEmbeded;
  1450. begin
  1451.     try
  1452.        Screen.Cursor := crHourglass;
  1453.        Application.CreateForm(TfrmEmbed, frmEmbed);
  1454.     finally
  1455.        Screen.Cursor := crDefault;
  1456.     end;
  1457.     try
  1458.     begin
  1459.        frmEmbed.sCurrentText := SelText;
  1460.        frmEmbed.ShowModal;
  1461.        if Length(frmEmbed.sCurrentText) > 0 then
  1462.           AddText(frmEmbed.sCurrentText, '', False);
  1463.     end;
  1464.     finally
  1465.        frmEmbed.Free;
  1466.     end;
  1467. end;
  1468.  
  1469. procedure TfrmDoc.DocDate;
  1470. begin
  1471.      AddText(DateToStr(Date) + ' ' + TimeToStr(Time), '', False);
  1472. end;
  1473.  
  1474. procedure TfrmDoc.DocHotdogVersion;
  1475. begin
  1476.      AddText('HotDog Professional 5', '', False);
  1477. end;
  1478.  
  1479. procedure TfrmDoc.DocCurrentFilename;
  1480. begin
  1481.      if sDocFilename <> '' then
  1482.         AddText(sDocFileName, '', False)
  1483.      else
  1484.         AddText('Untitled', '', False);
  1485. end;
  1486.  
  1487. procedure TfrmDoc.DocWindowsVersion;
  1488. begin
  1489.      if  Win32Platform = VER_PLATFORM_WIN32s then
  1490.         AddText('Windows 3.1', '',  False)
  1491.      else if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
  1492.         AddText('Windows 95', '',  False)
  1493.      else if Win32Platform = VER_PLATFORM_WIN32_NT then
  1494.        AddText('Windows NT', '', False);
  1495. end;
  1496.  
  1497. procedure TfrmDoc.DocUserName;
  1498. begin
  1499.    tReg.CloseKey;
  1500.    tReg.RootKey := HKEY_LOCAL_MACHINE;
  1501.    if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
  1502.    begin
  1503.             tReg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion', False);
  1504.             if LowerCase(ReadRegString('RegisteredOwner')) <> 'keynotexist' then
  1505.                AddText(ReadRegString('RegisteredOwner'), '', False);
  1506.    end
  1507.    Else if Win32Platform = VER_PLATFORM_WIN32_NT then
  1508.    begin
  1509.            tReg.OpenKey('\SOFTWARE\Microsoft\Windows NT\CurrentVersion', False);
  1510.            if LowerCase(ReadRegString('RegisteredOwner')) <> 'keynotexist' then
  1511.                AddText(ReadRegString('RegisteredOwner'), '', False);
  1512.    end;
  1513. end;
  1514.  
  1515. procedure TfrmDoc.DocCompanyName;
  1516. begin
  1517.    tReg.CloseKey;
  1518.    tReg.RootKey := HKEY_LOCAL_MACHINE;
  1519.    if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
  1520.    begin
  1521.             tReg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion', False);
  1522.             if LowerCase(ReadRegString('RegisteredOwner')) <> 'keynotexist' then
  1523.                AddText(ReadRegString('RegisteredOrganization'), '', False);
  1524.    end
  1525.    Else if Win32Platform = VER_PLATFORM_WIN32_NT then
  1526.    begin
  1527.            tReg.OpenKey('\SOFTWARE\Microsoft\Windows NT\CurrentVersion', False);
  1528.            if LowerCase(ReadRegString('RegisteredOwner')) <> 'keynotexist' then
  1529.                AddText(ReadRegString('RegisteredOrganization'), '', False);
  1530.    end;
  1531. end;
  1532.  
  1533. function TfrmDoc.GetPreviewFileName: String;
  1534. var
  1535.     sReturn: String;
  1536. begin
  1537.     if Length(sDocFileName) = 0 then
  1538.         sReturn := sPreviewFileName
  1539.     else
  1540.         //sReturn := ExtractFilePath(sDocFileName) + '~hd4preview.html';
  1541.         sReturn := ExtractFilePath(sDocFileName) + '~hdprev.htm'; //- Sav 01-09-97 for Novell Server
  1542.     //Return Data
  1543.     Result := sReturn;
  1544. end;
  1545.  
  1546. procedure TfrmDoc.HideRover;
  1547. var
  1548.    sFileName: String;
  1549.     //bResult: Boolean;
  1550. begin
  1551.     sFileName := GetPreviewFileName;
  1552.     if Rover.Visible then
  1553.         Rover.ClearView;
  1554.     if FileExists(sFileName) then
  1555.         //bResult := DeleteFile(sFileName);
  1556. end;
  1557.  
  1558. function TfrmDoc.GetBodyTag : String;
  1559. var
  1560.     iStart: Integer;
  1561.     iEnd: Integer;
  1562. begin
  1563.     iStart := Find('<BODY', 0, False, False);
  1564.     if iStart > -1 Then
  1565.     begin
  1566.         iEnd := Find('>', iStart, False, False);
  1567.         if iEnd > -1 Then
  1568.         begin
  1569.             result := Document.GetTextRange(iStart, iEnd);
  1570.         end;
  1571.     end;
  1572.  
  1573. end;
  1574. procedure TfrmDoc.UpdateBodyTag(sBodyTag: String);
  1575. var
  1576.     iStart: Integer;
  1577.     iEnd: Integer;
  1578. begin
  1579.     //Find(sString: String; iStart: Integer; bCase: Boolean; bWholeWord: Boolean): LongInt;
  1580.     iStart := Find('<BODY', 0, False, False);
  1581.     if iStart > -1 Then
  1582.     begin
  1583.         iEnd := Find('>', iStart, False, False);
  1584.         if iEnd > -1 Then
  1585.         begin
  1586.             Document.ReplaceText(iStart, (iEnd - iStart) + 1, sBodyTag);
  1587.             if (MainForm is TfrmMainRover) then
  1588.                 (MainForm as TfrmMainRover).UpdateRover;
  1589.             //UpdateRover;
  1590.         end;
  1591.     end;
  1592. end;
  1593.  
  1594. //procedure TfrmDoc.RecentFilesItemClick(Sender: TObject); {Hint}
  1595. {var
  1596.     sFilename: string;
  1597.     tmpDoc: ^TfrmDoc;}
  1598. //begin {Hint}
  1599.     {sFilename := (Sender as TMenuItem).Caption;
  1600.     sFileName := ChopAfter(sFilename, ' ');
  1601.     if MDI.MDIChildCount > 0 then
  1602.     begin
  1603.         if MDI.FindDocument(sFileName) = nil then
  1604.         begin
  1605.             //tmpDoc := TfrmDoc.Create(MainForm);
  1606.             tmpDoc := CreateDocWindow;
  1607.             tmpDoc.OpenDoc(sFileName);
  1608.         end
  1609.         else
  1610.         begin
  1611.             MDI.FindDocument(sFileName).BringToFront;
  1612.             MDI.FindDocument(sFileName).SetFocus;
  1613.         end;
  1614.     end
  1615.     else
  1616.     begin
  1617.         //tmpDoc := TfrmDoc.Create(MainForm);
  1618.         tmpDoc := CreateDocWindow;
  1619.         tmpDoc.OpenDoc(sFileName);
  1620.     end;}
  1621. //end; {Hint}
  1622.  
  1623. {procedure TfrmDoc.SetChildNum(I: Integer);
  1624. begin
  1625.     //iChildNum := I;
  1626. end;} {Hint}
  1627.  
  1628. procedure TfrmDoc.DocCut;
  1629. begin
  1630.     rtfDoc.Cut;
  1631.     HideToolbarShit(True);
  1632. end;
  1633.  
  1634. procedure TfrmDoc.DocCopy;
  1635. begin
  1636.     rtfDoc.Copy;
  1637.     HideToolbarShit(True);
  1638. end;
  1639.  
  1640. procedure TfrmDoc.DocPaste;
  1641. begin
  1642.     rtfDoc.Paste;
  1643.     HideToolbarShit(True);
  1644. end;
  1645.  
  1646. procedure TfrmDoc.DocPasteTable;
  1647. begin
  1648.   SelText := GenerateTable(GetClipboardContents);
  1649. end;
  1650.  
  1651. procedure TfrmDoc.DocPasteLeftAligned;
  1652. var
  1653.    sText : String;
  1654.    i : Integer;
  1655.    strLines : TStringList;
  1656. begin
  1657.      strLines := TStringList.Create;
  1658.      try
  1659.         sText := GetClipboardContents;
  1660.         ParseLine(sText, #13#10, strLines);
  1661.         sText := '';
  1662.         for i := 0 to strLines.Count -1 do
  1663.              sText := sText + TrimLeft(strLines.Strings[i]) + #13#10;
  1664.         sText := ReplaceString(sText, #13#10 + #13#10, '@SSPlaceHolder');
  1665.         sText := ReplaceString(sText, #13#10, ' ');
  1666.         sText := ReplaceString(sText, '@SSPlaceHolder', #13#10+#13#10);
  1667.      finally
  1668.         strLines.Free;
  1669.      end;
  1670.      SelText := sText;
  1671. end;
  1672.  
  1673.  
  1674. procedure TfrmDoc.DocUndo;
  1675. begin
  1676.     rtfDoc.Undo;
  1677.     //rtfDoc.UndoManager.Undo; //kin 190997
  1678.     HideToolbarShit(True);
  1679. end;
  1680.  
  1681. procedure TfrmDoc.DocRedo;
  1682. begin
  1683.     //rtfDoc.UndoManager.Redo; //kin 190997
  1684.     rtfDoc.Redo;
  1685.     HideToolbarShit(True);
  1686. end;
  1687.  
  1688. procedure TfrmDoc.DocFind;
  1689. begin
  1690.     {iLastfind := SelStart;
  1691.     dlgFind.Execute;}
  1692.     dlgFind := TFindDialog.Create(Self);
  1693.     dlgFind.Options := [frDown,frHideWholeWord,frHideUpDown];
  1694.     dlgFind.OnFind := dlgFindFind;
  1695.     FindReplace.Find;
  1696.     dlgFind.Free;
  1697. end;
  1698.  
  1699. procedure TfrmDoc.DocFindF3;
  1700. begin
  1701.     if SelLength > 0 then
  1702.         FindReplace.FindNextF3(SelStart + SelLength)
  1703.     else
  1704.         FindReplace.FindNextF3(SelStart);
  1705. end;
  1706.  
  1707. procedure TfrmDoc.InsertList;
  1708. var
  1709.     sEnd: String;
  1710.     iPos: Integer;
  1711. begin
  1712.     try
  1713.        Screen.Cursor := crHourglass;
  1714.        Application.CreateForm(TfrmDocList, frmDocList);
  1715.     finally
  1716.        Screen.Cursor := crDefault;
  1717.     end;
  1718.     if tCurrentElement.iType <> HTMLSYNTAXELEMENT_INVALID then
  1719.     begin
  1720.         if tCurrentElement.sTagName = 'Bulleted List' then
  1721.             sEnd := '</ul>'
  1722.         else if tCurrentElement.sTagName = 'Numbered List' then
  1723.             sEnd := '</ol>'
  1724.         else if tCurrentElement.sTagName = 'Definition List' then
  1725.             sEnd := '</dl>';
  1726.         if sEnd <> '' then
  1727.         begin
  1728.             iPos := Document.FindString(tCurrentElement.iStart, Document.Length - 1, sEnd, True, False, False);
  1729.             if iPos > -1 then
  1730.             begin
  1731.                 rtfDoc.SetSelection(tCurrentElement.iStart, iPos + Length(sEnd));
  1732.                 frmDocList.sTag := Document.GetTextRange(tCurrentElement.iStart, iPos + Length(sEnd));
  1733.             end;
  1734.         end;
  1735.     end
  1736.     else if SelLength > 0 then
  1737.     begin
  1738.         frmDocList.sTag := SelText;
  1739.     end;
  1740.     frmDocList.ShowModal;
  1741.     if Length(frmDocList.sList) > 0 then
  1742.         AddText(frmDocList.sList, '', False);
  1743.     ClearCurrentElement;
  1744. end;
  1745.  
  1746. procedure TfrmDoc.DocList;
  1747. begin
  1748.     try
  1749.        Screen.Cursor := crhourglass;
  1750.        Application.CreateForm(TfrmDocList, frmDocList);
  1751.     finally
  1752.        Screen.Cursor := crDefault
  1753.     end;
  1754.     if SelLength > 0 then
  1755.         frmDocList.sTag := SelText;
  1756.     frmDocList.ShowModal;
  1757.     if Length(frmDocList.sList) > 0 then
  1758.         AddText(frmDocList.sList, '', False);
  1759. end;
  1760.  
  1761. procedure TfrmDoc.DocDefList;
  1762. begin
  1763.      Application.CreateForm(TfrmDefList, frmDefList);
  1764.      frmDefList.sTag := SelText;
  1765.      ModalResult := frmDefList.ShowModal;
  1766.      if ModalResult = mrOk then
  1767.        SelText := frmDefList.sTag;
  1768. end;
  1769.  
  1770. (*
  1771. procedure TfrmDoc.BullList;
  1772. {var
  1773.     sEnd: String;
  1774.     iPos: Integer;}
  1775. begin
  1776.     Application.CreateForm(TfrmDocList, frmDocList);
  1777.     if SelLength > 0 then
  1778.     begin
  1779.         frmDocList.sTag := SelText;
  1780.     end;
  1781.     frmDocList.ListStyle := LIST_BULLET;
  1782.     frmDocList.ShowModal;
  1783.     if Length(frmDocList.sList) > 0 then
  1784.         AddText(frmDocList.sList, '', False);
  1785. end;
  1786.  
  1787. procedure TfrmDoc.NumList;
  1788. {var
  1789.     sEnd: String;
  1790.     iPos: Integer;}
  1791. begin
  1792.     Application.CreateForm(TfrmDocList, frmDocList);
  1793.     if SelLength > 0 then
  1794.     begin
  1795.         frmDocList.sTag := SelText;
  1796.     end;
  1797.     frmDocList.ListStyle := LIST_NUMBERED;
  1798.     frmDocList.ShowModal;
  1799.     if Length(frmDocList.sList) > 0 then
  1800.         AddText(frmDocList.sList, '', False);
  1801. end;
  1802. *)
  1803.  
  1804. procedure TfrmDoc.DocFont(bFromRightClick : Boolean);
  1805. //returns false if the font dialog is cancelled
  1806. var
  1807.     tElement: Variant;
  1808.     //iTextStart: Integer;
  1809.     //iTextEnd: Integer;
  1810.     iNext, iPos, iStart: Integer;
  1811.     sCurrent: String;
  1812.     sTagText: String;
  1813.     bGalvies: Boolean;
  1814.     sBegin, sEnd: String;    //beginning and end of Font tag, inc. <b> </b> etc
  1815. begin
  1816.     //We dont want to run this code all the time, because tCurrentElement will be out of sync
  1817.     if bFromRightClick then
  1818.     begin
  1819.        if tCurrentElement.iType <> HTMLSYNTAXELEMENT_INVALID then
  1820.        begin
  1821.            sEnd := '</font>';
  1822.            iPos := Document.FindString(tCurrentElement.iStart, Document.Length - 1, sEnd, True, False, False);
  1823.            if iPos > -1 then
  1824.            begin
  1825.                //Find text
  1826.                iNext := tCurrentElement.iStart;
  1827.                repeat
  1828.                    tElement := Document.GetElementAt(iNext, iStart);
  1829.                    iNext := iStart + tElement.Length;
  1830.                until tElement.Type = HTMLSYNTAXELEMENT_TEXT;
  1831.                //iTextStart := iStart;
  1832.                repeat
  1833.                    tElement := Document.GetElementAt(iNext, iStart);
  1834.                    iNext := iStart + tElement.Length;
  1835.                until tElement.Type = HTMLSYNTAXELEMENT_TAG;
  1836.                //iTextEnd := iStart;
  1837.  
  1838.                //sTagText := Document.GetTextRange(iTextStart, iTextEnd);
  1839.  
  1840.                rtfDoc.SetSelection(tCurrentElement.iStart, iPos + Length(sEnd));
  1841.                sCurrent := Document.GetTextRange(tCurrentElement.iStart, iPos + Length(sEnd));
  1842.                //bGalvies := False;
  1843.            end
  1844.            else
  1845.            begin
  1846.                rtfDoc.SetSelection(tCurrentElement.iStart, tCurrentElement.iLength);
  1847.                sCurrent := Document.GetTextRange(tCurrentElement.iStart, tCurrentElement.iLength);
  1848.                //bGalvies := True;
  1849.            end;
  1850.        end;
  1851.     end;
  1852.     //else}
  1853.     //begin
  1854.     bGalvies := False;
  1855.     //Check if current <FONT> </FONT> tags are selected
  1856.     sCurrent := GetTag(SelText, '<font', '</font>');
  1857.     if Length(sCurrent) = 0 then
  1858.     begin
  1859.         //see if just <FONT> tag is selected
  1860.         sCurrent := GetTag(SelText, '<font', '>');
  1861.         if Length(sCurrent) > 0 then
  1862.             bGalvies := True;
  1863.     end;
  1864.     //end;
  1865.  
  1866.     Application.CreateForm(TfrmFontDlg, frmFontDlg);
  1867.     try
  1868.        if Length(sCurrent) > 0 then
  1869.        begin
  1870.            frmFontDlg.HTMLFont := ParseForFont(sCurrent);
  1871.            frmFontDlg.sTagGuts := GetTagGuts(sCurrent, '>', '</font>');
  1872.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<strong>', '');
  1873.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</strong>', '');
  1874.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<b>', '');
  1875.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</b>', '');
  1876.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<em>', '');
  1877.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</em>', '');
  1878.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<i>', '');
  1879.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</i>', '');
  1880.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<u>', '');
  1881.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</u>', '');
  1882.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<sup>', '');
  1883.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</sup>', '');
  1884.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<sub>', '');
  1885.            frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</sub>', '');
  1886.        end
  1887.        else
  1888.            sTagText := SelText;
  1889.  
  1890.        frmFontDlg.ShowModal;
  1891.  
  1892.        if frmFontDlg.ModalResult = mrOK then
  1893.        begin
  1894.            BuildFontTag(frmFontDlg.HTMLFont, sBegin, sEnd);
  1895.            if bGalvies then
  1896.               AddText(sBegin, sEnd, False)
  1897.            else
  1898.            begin
  1899.               if sTagText = frmFontDlg.sTagGuts then
  1900.                    AddText(sBegin + sTagText, sEnd, False)
  1901.               else
  1902.                    AddText(sBegin + sTagText + frmFontDlg.sTagGuts, sEnd, False);
  1903.            end;
  1904.        end;
  1905.        ClearCurrentElement;
  1906.     finally
  1907.         frmFontDlg.Free;
  1908.     end;
  1909. end;
  1910.  
  1911. function TfrmDoc.ParseForFont(sText: String): THTMLFont;
  1912. var
  1913.     tmpFont: THTMLFont;
  1914. begin
  1915.     tmpFont.Style := [];
  1916.     //tmpFont := TFont.Create;
  1917.     tmpFont.Name := GetAttribute(sText, 'Face');
  1918.     tmpFont.Size := GetAttribute(sText, 'Size');
  1919.     tmpFont.Color := HTMLToColor(GetAttribute(sText, 'Color'));
  1920.     //(fsBold, fsItalic, fsUnderline, fsSuperscript, fsSubscript, fsBlink);
  1921.     if (Length(GetTag(LowerCase(sText), '<b>', '</b>'))) or (Length(GetTag(LowerCase(sText), '<strong>', '</strong>'))) > 0 then
  1922.         tmpFont.Style := tmpFont.Style + [hfsBold];
  1923.     if (Length(GetTag(LowerCase(sText), '<i>', '</i>'))) or (Length(GetTag(LowerCase(sText), '<em>', '</em>'))) > 0 then
  1924.         tmpFont.Style := tmpFont.Style + [hfsItalic];
  1925.     if Length(GetTag(LowerCase(sText), '<u>', '</u>')) > 0 then
  1926.         tmpFont.Style := tmpFont.Style + [hfsUnderline];
  1927.     if Length(GetTag(LowerCase(sText), '<sup>', '</sup>')) > 0 then
  1928.         tmpFont.Style := tmpFont.Style + [hfsSuperscript];
  1929.     if Length(GetTag(LowerCase(sText), '<sub>', '</sub>')) > 0 then
  1930.         tmpFont.Style := tmpFont.Style + [hfsSubscript];
  1931.     if Length(GetTag(LowerCase(sText), '<blink>', '</blink>')) > 0 then
  1932.         tmpFont.Style := tmpFont.Style + [hfsBlink];
  1933.  
  1934.     //Return Result
  1935.     Result := tmpFont;
  1936. end;
  1937.  
  1938. procedure TfrmDoc.AddText(sText, sEnd: String; bSkipRemoval: Boolean);
  1939. var
  1940.     bBoth: Boolean;
  1941.     lWhere: LongInt;
  1942.     bKeepHighlight: Boolean;
  1943.     lCurrSelLength: LongInt;
  1944.     lCurrSelText: String;
  1945.     //iAddCR: Integer;
  1946.     bRemoval: Boolean;
  1947.     sNewText: String;
  1948. begin
  1949.     bKeepHighLight := False;
  1950.     bBoth := False;
  1951.     //iAddCR := 0;
  1952.     bRemoval := False;
  1953.  
  1954.     lWhere := selStart;
  1955.     lCurrSelLength := selLength;
  1956.     lCurrSelText := SelText;
  1957.  
  1958.     if lCurrSelLength > 0 Then
  1959.         bKeepHighlight := True;
  1960.  
  1961.     if (Length(sText) > 0) And (Length(sEnd) > 0) And (lCurrSelLength = 0) Then
  1962.         bBoth := True;    //if end tag exists and nothing is highlighted,
  1963.                         //set cursor between the tags
  1964.  
  1965.     sNewText := SelText;
  1966.     while Right(sNewText, 2) = #13#10 do
  1967.     begin
  1968.         sNewText := ChopString(sNewText, 2);
  1969.         //Inc(iAddCR);
  1970.     end;
  1971.  
  1972.     if not(bSkipRemoval) then
  1973.         if RemoveExistingTags(sText, sEnd) Then
  1974.             bRemoval := True;
  1975.  
  1976.     //Add the Text
  1977.     sNewText := sText;
  1978.     If Not bRemoval Then
  1979.         sNewText := sNewText + sEnd;
  1980.  
  1981.     {while iAddCr > 0 do
  1982.     begin
  1983.         sNewText := sNewText + #13#10;
  1984.         Dec(iAddCr);
  1985.     end;}
  1986.  
  1987.     SelText := sNewText;
  1988.  
  1989.     //LockWindowUpdate(MainForm.Handle);
  1990.  
  1991.     If bKeepHighlight Then
  1992.     begin
  1993.         rtfDoc.SetSelection(lWhere, lWhere + Length(sNewText));
  1994.     end
  1995.     else
  1996.     begin
  1997.         If bBoth Then
  1998.             SetCursorPos(lWhere + Length(sText))
  1999.         else
  2000.             SetCursorPos(lWhere + Length(sNewText));
  2001.     end;
  2002.     if (Rover.TagRefresh) and (MainForm is TfrmMainRover) then
  2003.         (MainForm as TfrmMainRover).PosRefreshRover(PreviewFileName, Text);
  2004.  
  2005.     //LockWindowUpdate(0);
  2006. end;
  2007.  
  2008. procedure TfrmDoc.DocBold;
  2009. begin
  2010.     if tOptions.HTMLStrongTag then
  2011.         AddText(tOptions.TagCase('<STRONG>') + SelText, tOptions.TagCase('</STRONG>'), False)
  2012.     else
  2013.         AddText(tOptions.TagCase('<B>') + SelText, tOptions.TagCase('</B>'), False);
  2014. end;
  2015.  
  2016. procedure TfrmDoc.DocItalic;
  2017. begin
  2018.     if tOptions.HTMLEMTag then
  2019.         AddText(tOptions.TagCase('<EM>') + SelText, tOptions.TagCase('</EM>'), False)
  2020.     else
  2021.         AddText(tOptions.TagCase('<I>') + SelText, tOptions.TagCase('</I>'), False);
  2022. end;
  2023.  
  2024. procedure TfrmDoc.DocUnderline;
  2025. begin
  2026.     AddText(tOptions.TagCase('<U>') + SelText, tOptions.TagCase('</U>'), False);
  2027. end;
  2028.  
  2029. procedure TfrmDoc.DocCenter;
  2030. begin
  2031.     AddText(tOptions.TagCase('<CENTER>') + SelText, tOptions.TagCase('</CENTER>'), False);
  2032. end;
  2033.  
  2034. procedure TfrmDoc.DocPara;
  2035. begin
  2036.     if tOptions.ParaContainer then
  2037.         AddText(tOptions.TagCase('<P>') + SelText, tOptions.TagCase('</P>'), False)
  2038.     else
  2039.         AddToSelText(tOptions.TagCase('<P>'));
  2040. end;
  2041.  
  2042. procedure TfrmDoc.DocBreak;
  2043. var
  2044.     sText : String;
  2045. begin
  2046.      sText := SelText;
  2047.      SelText := '';
  2048.      if sText = '' then
  2049.         InsertText('<BR>', SelStart)
  2050.      else
  2051.      begin
  2052.         if Pos(#13#10, sText) > 0 then
  2053.         begin
  2054.            //SelText := ReplaceString(SelText, #13#10, '<BR>'+ #13#10);
  2055.            sText := ReplaceString(sText, #13#10, '<BR>'+ #13#10) + '<BR>';
  2056.            InsertText(sText, SelStart);
  2057.         end
  2058.         //the text that is selected is going to be deleted by the return keypress,
  2059.         //(even though key is set to 0) so add it back.
  2060.         else
  2061.            InsertText(sText + '<BR>', SelStart);
  2062.            // SelText := SelText + '<BR>';
  2063.      end;
  2064. end;
  2065.  
  2066. procedure TfrmDoc.DocNOBR;
  2067. begin
  2068.     AddToSelText(tOptions.TagCase(' '));
  2069. end;
  2070.  
  2071. procedure TfrmDoc.AddToSelText(sText: String);
  2072. var
  2073.     iWhere: Integer;
  2074.     iCurrSelLength: Integer;
  2075. begin
  2076.     iWhere := selStart;
  2077.     iCurrSelLength := selLength;
  2078.     SelText := SelText + sText;
  2079.  
  2080.     if iCurrSelLength > 0 then
  2081.     begin
  2082.         SetSelection(iWhere, iCurrSelLength + Length(sText));
  2083.     end
  2084.     else
  2085.         SetCursorPos(iWhere + Length(sText));
  2086. end;
  2087.  
  2088. procedure TfrmDoc.DocPrintSetup;
  2089. begin
  2090.     if Printer.Printers.Count = 0 then
  2091.         MessageDlg('There are currently no installed printers.' +
  2092.                     'You will need to install a Windows printer to print the document.',
  2093.                     mtInformation, [mbOK], 0)
  2094.     else
  2095.         rtfDoc.PageSetup;
  2096. end;
  2097. procedure TfrmDoc.DocPrint;
  2098. //var -sav
  2099.    //iPixPerInch, iTwips: Integer;
  2100.    //rtfTemp: TRichEdit; -sav
  2101.    //tr: TRect;
  2102.    //DC: hDC;
  2103. begin
  2104.     if Printer.Printers.Count = 0 then
  2105.         MessageDlg('There are currently no installed printers.' +
  2106.                     'You will need to install a Windows printer to print the document.',
  2107.                     mtError, [mbOK], 0)
  2108.     else
  2109.         rtfdoc.Print(sDocFilename);
  2110.     (*else if dlgPrint.Execute then
  2111.     begin
  2112.         rtfTemp := TRichEdit.Create(Self);
  2113.         try
  2114.             Screen.Cursor := crHourglass;
  2115.             rtfTemp.Visible := False;
  2116.             rtfTemp.Parent := Self;
  2117.             rtfTemp.Width := rtfDoc.Width;
  2118.             rtfTemp.Height := rtfDoc.Height;
  2119.  
  2120.             rtfTemp.Text := Document.Text;
  2121.             rtfTemp.WordWrap := rtfDoc.WordWrap;
  2122.             rtfTemp.Font.Name := rtfDoc.EditFont.Name;
  2123.             rtfTemp.Font.Size := rtfDoc.EditFont.Size;
  2124.  
  2125.             {DC := GetDC(rtfDoc.HWnd);
  2126.             iPixPerInch := GetDeviceCaps(DC, LOGPIXELSX);
  2127.             ReleaseDC(rtfDoc.HWnd, DC);
  2128.             iTwips := (rtfDoc.ColumnMax / iPixPerInch) * 1440;
  2129.  
  2130.             tr := rtfTemp.PageRect;
  2131.             tr.Right := iTwips;
  2132.             rtfTemp.PageRect := tr;}
  2133.  
  2134.             Status('Printing document...');
  2135.             rtfTemp.Print(sDocFileName);
  2136.         finally
  2137.             Status('');
  2138.             Screen.Cursor := crDefault;
  2139.             rtfTemp.Free;
  2140.         end;
  2141.     end;*)
  2142. end;
  2143.  
  2144. procedure TfrmDoc.KillTmpFile;
  2145. begin
  2146.     if FileExists(sBackupFileName) then
  2147.         DeleteFile(sBackupFileName);
  2148. end;
  2149.  
  2150. {function TfrmDoc.CleanSaveAsName(sName, sDefExt: String): String;
  2151. var
  2152.     //Damned common dialog...appends default extension if it is different
  2153.     iFirstDot: Integer;
  2154.     iExt: Integer;
  2155. begin
  2156.     iExt := Pos('.' + sDefExt, sName);
  2157.     iFirstDot := Pos('.', sName);
  2158.     If (iExt > 0) And (iFirstDot > 0) Then
  2159.         If iExt <> iFirstDot Then
  2160.             //DOH ! two extensions - clean out the default
  2161.             subReplaceString(sName, '.' + sDefExt, '', True);
  2162.     Result := sName;
  2163. end;} {Hint}
  2164.  
  2165. procedure TfrmDoc.BuildFontTag(tmpFont: THTMLFont; var sBegin, sEnd: String);
  2166. begin
  2167.     sBegin := tOptions.TagCase('<FONT');
  2168.     if Length(tmpFont.Name) > 0 then
  2169.         sBegin := sBegin + tOptions.TagCase(' FACE="') + tmpFont.Name + '"';
  2170.     if tmpFont.Size <> '' then
  2171.         sBegin := sBegin + tOptions.TagCase(' SIZE="') + tmpFont.Size + '"';
  2172.     if tmpFont.Color > 0 then
  2173.         sBegin := sBegin + tOptions.TagCase(' COLOR="#') + GetHexColourStr(tmpFont.Color) + '"';
  2174.     sBegin := sBegin + '>';
  2175.     sEnd := tOptions.TagCase('</FONT>');
  2176.  
  2177.     if hfsBold in tmpFont.Style then
  2178.     begin
  2179.         if tOptions.HTMLStrongTag then
  2180.         begin
  2181.            sBegin := sBegin + tOptions.TagCase('<STRONG>');
  2182.            sEnd := tOptions.TagCase('</STRONG>') + sEnd;
  2183.         end
  2184.         else
  2185.         begin
  2186.            sBegin := sBegin + tOptions.TagCase('<B>');
  2187.            sEnd := tOptions.TagCase('</B>') + sEnd;
  2188.         end;
  2189.     end;
  2190.     if hfsItalic in tmpFont.Style then
  2191.     begin
  2192.         if tOptions.HTMLEMTag then
  2193.         begin
  2194.            sBegin := sBegin + tOptions.TagCase('<EM>');
  2195.            sEnd := tOptions.TagCase('</EM>') + sEnd;
  2196.         end
  2197.         else
  2198.         begin
  2199.            sBegin := sBegin + tOptions.TagCase('<I>');
  2200.            sEnd := tOptions.TagCase('</I>') + sEnd;
  2201.         end;
  2202.     end;
  2203.     if hfsUnderline in tmpFont.Style then
  2204.     begin
  2205.         sBegin := sBegin + tOptions.TagCase('<U>');
  2206.         sEnd := tOptions.TagCase('</U>') + sEnd;
  2207.     end;
  2208.     if hfsSuperscript in tmpFont.Style then
  2209.     begin
  2210.         sBegin := sBegin + tOptions.TagCase('<SUP>');
  2211.         sEnd := tOptions.TagCase('</SUP>') + sEnd;
  2212.     end;
  2213.     if hfsSubscript in tmpFont.Style then
  2214.     begin
  2215.         sBegin := sBegin + tOptions.TagCase('<SUB>');
  2216.         sEnd := tOptions.TagCase('</SUB>') + sEnd;
  2217.     end;
  2218.     if hfsBlink in tmpFont.Style then
  2219.     begin
  2220.         sBegin := sBegin + tOptions.TagCase('<BLINK>');
  2221.         sEnd := tOptions.TagCase('</BLINK>') + sEnd;
  2222.     end;
  2223. end;
  2224.  
  2225. (*
  2226. procedure TfrmDoc.InsertLink(Mode: modeInsert);
  2227. var
  2228.     sCurrent: String;
  2229.     sTagText: String;
  2230.     bGalvies: Boolean;
  2231. begin
  2232.     bGalvies := False;
  2233.     //Check if current <A HREF> </A> tags are selected
  2234.     sCurrent := GetTag(LowerCase(SelText), '<a href', '</a>');
  2235.     if Length(sCurrent) = 0 then
  2236.     begin
  2237.         //see if just <A HREF> tag is selected
  2238.         sCurrent := GetTag(LowerCase(SelText), '<a href', '>');
  2239.         if Length(sCurrent) > 0 then
  2240.             bGalvies := True;
  2241.     end;
  2242.     if Length(sCurrent) > 0 then
  2243.     begin
  2244.         if Not(bGalvies) then
  2245.             sTagText := Between(LowerCase(sCurrent), '>', '</a>');
  2246.     end
  2247.     else
  2248.         sTagText := SelText;
  2249.  
  2250.     Application.CreateForm(TfrmLink, frmLink);
  2251.     frmLink.sCurrent := sCurrent;
  2252.     frmLink.sText := sTagText;
  2253.     frmLink.Mode := Mode;
  2254.     frmLink.sFileName := sDocFileName;
  2255.     frmLink.ShowModal;
  2256.     if frmLink.ModalResult = mrOK then
  2257.     begin
  2258.         //AddText(sText, sEnd, bSkipRemoval);
  2259.         if bGalvies then
  2260.             AddText(frmLink.sLink + frmLink.sText, '', True)
  2261.         else
  2262.             AddText(frmLink.sLink + frmLink.sText, '</A>', True);
  2263.     end;
  2264.     frmLink.Release;
  2265. end;
  2266. *)
  2267. procedure TfrmDoc.InsertLink(Mode : modeInsert);
  2268. var
  2269.     sCurrent: String;
  2270.     sTagText: String;
  2271.     bGalvies: Boolean;
  2272. begin
  2273.     bGalvies := False;
  2274.     //Check if current <A HREF> </A> tags are selected
  2275.      sCurrent := GetTag(SelText, '<a href', '</a>');         (*mg261197 removed lowercase *)
  2276.     if Length(sCurrent) = 0 then
  2277.     begin
  2278.      //see if just <A HREF> tag is selected
  2279.      sCurrent := GetTag(SelText, '<a href', '>');           (*mg261197 removed lowercase *)
  2280.         if Length(sCurrent) > 0 then
  2281.          bGalvies := True;
  2282.     end;
  2283.     if Length(sCurrent) > 0 then
  2284.     begin
  2285.         if Not(bGalvies) then
  2286.          sTagText := Between(sCurrent, '>', '</a>');
  2287.     end
  2288.     else
  2289.       sTagText := SelText;
  2290.  
  2291.     Screen.Cursor := crhourglass;
  2292.     Application.CreateForm(TfrmLink, frmLink);
  2293.     Screen.Cursor := crDefault;
  2294.     try
  2295.        frmLink.sCurrent := sCurrent;
  2296.        frmLink.sText := sTagText;
  2297.        frmLink.Mode := Mode;
  2298.        frmLink.sFileName := sDocFileName;
  2299.        frmLink.ShowModal;
  2300.        if frmLink.ModalResult = mrOK then
  2301.        begin
  2302.            //AddText(sText, sEnd, bSkipRemoval);
  2303.            {if bGalvies then
  2304.               AddText(frmLink.sLink + frmLink.sText, '', False)
  2305.            else
  2306.               AddText(frmLink.sLink + frmLink.sText, tOptions.TagCase('</A>'), False);
  2307.            }
  2308.            AddText(frmLink.sLink, '', False);
  2309.        end;
  2310.     finally
  2311.         frmLink.Release;
  2312.     end;
  2313. end;
  2314.  
  2315. procedure TfrmDoc.DocBigFirst;
  2316. var
  2317.     sText: String;
  2318.     sTag: String;
  2319. begin
  2320.     sTag := tOptions.TagCase('<FONT SIZE="+1">');
  2321.     sText := SelText;
  2322.     if Length(SelText) > 0 then
  2323.     begin
  2324.         sTag := sTag + sText[1];
  2325.         sText := Copy(SelText, 2, SelLength);
  2326.     end;
  2327.     SelText := sTag + tOptions.TagCase('</FONT>') + sText;
  2328.     //AddText(sTag + sText, '</FONT>', False);
  2329. end;
  2330.  
  2331. procedure TfrmDoc.Center1Click(Sender: TObject);
  2332. begin
  2333.     DocCenter;
  2334. end;
  2335.  
  2336. procedure TfrmDoc.InsertLine;
  2337. var
  2338.     sCurrent: String;
  2339. begin
  2340.     //Check if current <HR> tags are selected
  2341.     //sCurrent := GetTag(LowerCase(SelText), '<hr', '>');
  2342.     sCurrent := SelText;
  2343.     try
  2344.        Screen.Cursor := crHourglass;
  2345.        Application.CreateForm(TfrmInsRule, frmInsRule);
  2346.     finally
  2347.        Screen.Cursor := crDefault;
  2348.     end;
  2349.     frmInsRule.sSelText := sCurrent;
  2350.     frmInsRule.ShowModal;
  2351.     if frmInsRule.ModalResult = mrOK then
  2352.     begin
  2353.         AddText(frmInsRule.sLineTag, '', False);
  2354.     end;
  2355. end;
  2356.  
  2357. procedure TfrmDoc.DocPreview;
  2358. var
  2359.     sBrowser: String;
  2360.     sList: TStringList;
  2361. begin
  2362.     //Find Browser
  2363.     if tReg.OpenTo(INI_OPTIONS_BROWSERS, False) then
  2364.     begin
  2365.         sList := TStringList.Create;
  2366.         try
  2367.         begin
  2368.             tReg.GetValueNames(sList);
  2369.             if sList.Count > 0 then
  2370.                 sBrowser := tReg.ReadString(sList.Strings[0]);
  2371.         end
  2372.         finally
  2373.             sList.Free;
  2374.         end;
  2375.     end;
  2376.     //Preview
  2377.     //Document.SaveToFile(GetPreviewFileName);
  2378.     WriteWholeFile(GetPreviewFileName, Document.Text);
  2379.     mFilePreview(sBrowser, GetPreviewFileName);
  2380. end;
  2381.  
  2382. function TfrmDoc.DocPreviewWithBrowser(sBrowser: String) : boolean;
  2383. begin
  2384.     //Document.SaveToFile(GetPreviewFileName);
  2385.     WriteWholeFile(GetPreviewFileName, Document.Text);
  2386.     Result := mFilePreview(sBrowser, GetPreviewFileName);
  2387. end;
  2388.  
  2389. function TfrmDoc.DocPreviewWithLastBrowser : Boolean;
  2390. // Sav 01-09-97
  2391. //When F9 is pressed, preview using the last browser used.
  2392. var
  2393.     slBrowsers : TStringlist;
  2394. //    i : Integer;
  2395. begin
  2396.    result := False;
  2397.    try
  2398.        If (Trim(tOptions.LastBrowserUsed) <> '') and (FileExists(tOptions.LastBrowserUsed)) Then
  2399.        begin
  2400.            WriteWholeFile(GetPreviewFileName, Document.Text);
  2401.            mFilePreview(tOptions.LastBrowserUsed, GetPreviewFileName);
  2402.        end
  2403.        else
  2404.        begin
  2405.           //if there is no previous browser used, then grab the first one in the registry list.
  2406.           if tReg.OpenTo(INI_OPTIONS_BROWSERS, False) then
  2407.           begin
  2408.              slBrowsers := TStringList.Create;
  2409.              try
  2410.                tReg.GetValueNames(slBrowsers);
  2411.                if slBrowsers.Count > 0 then
  2412.                     result := DocPreviewWithBrowser(tReg.ReadString(slBrowsers.Strings[0]));
  2413.              finally
  2414.                slBrowsers.Free;
  2415.              end;
  2416.           end;
  2417.        end;
  2418.    except
  2419.    end;
  2420. end;
  2421.  
  2422. function TfrmDoc.SelStart: LongInt;
  2423. var
  2424.     lStart, lEnd: Integer;
  2425. begin
  2426.     if rtfDoc <> nil then
  2427.     begin
  2428.         lStart := rtfDoc.SelectionStart;
  2429.         lEnd := rtfDoc.SelectionEnd;
  2430.         Result := min_(lStart, lEnd);
  2431.     end
  2432.     else
  2433.         Result := 0;
  2434. end;
  2435.  
  2436. function TfrmDoc.SelEnd: LongInt;
  2437. var
  2438.     lStart, lEnd: Integer;
  2439. begin
  2440.     if rtfDoc <> nil then
  2441.     begin
  2442.         lStart := rtfDoc.SelectionStart;
  2443.         lEnd := rtfDoc.SelectionEnd;
  2444.         Result := min_(max_(lStart, lEnd), Document.Length - 1);
  2445.     end
  2446.     else
  2447.         Result := 0;
  2448. end;
  2449.  
  2450. function TfrmDoc.GetWordAtPos(iPos: Integer; var iStart, iEnd: Integer): String;
  2451. var
  2452.     iFirst, iLast: Integer;
  2453. begin
  2454.     rtfDoc.GetWordPosAtPos(iPos, iFirst, iLast);
  2455.     iStart := min_(iFirst, iLast);
  2456.     iEnd := max_(iFirst, iLast);
  2457.  
  2458.     iEnd := min_(iEnd, Document.Length);
  2459.  
  2460.     Result := Document.GetTextRange(iStart, iEnd);
  2461. end;
  2462.  
  2463. function TfrmDoc.GetNextTextBlock(var iStart: Integer): String;
  2464. var
  2465.     sResult: String;
  2466.     iCount: Integer;
  2467.     tElement: Variant;
  2468. begin
  2469.     Result := '';
  2470.     iCount := iStart;
  2471.     while iCount < Document.Length - 1 do
  2472.     begin
  2473.         try
  2474.             tElement := Document.GetElementAt(iCount, iStart);
  2475.             if tElement.Type <> HTMLSYNTAXELEMENT_TEXT then
  2476.                 iCount := iCount + tElement.Length //- 1
  2477.             else
  2478.             begin
  2479.                 //find in list and replace with tag
  2480.                 //if (iStart + tElement.Length {+ 1}) < Document.Length then
  2481.                 sResult := Document.GetTextRange(iStart, iStart + tElement.Length);
  2482.                 //else
  2483.                //     sResult := Document.GetTextRange(iStart, Document.Length);
  2484.  
  2485.                 if Length(Trim(sResult)) > 0 then
  2486.                 begin
  2487.                     Result := sResult;
  2488.                     iCount := Document.Length;
  2489.                 end
  2490.                 else
  2491.                     iCount := iCount + tElement.Length; //- 1;
  2492.             end;
  2493.         except
  2494.         end;
  2495.     end;
  2496. end;
  2497.  
  2498. function TfrmDoc.GetNextTag(var iStart: Integer): String;
  2499. var
  2500.     sResult: String;
  2501.     iCount: Integer;
  2502.     tElement: Variant;
  2503. begin
  2504.     Result := '';
  2505.     iCount := iStart;
  2506.     while iCount < Document.Length - 1 do
  2507.     begin
  2508.         try
  2509.             tElement := Document.GetElementAt(iCount, iStart);
  2510.             if tElement.Type <> HTMLSYNTAXELEMENT_TAG then
  2511.                 //iCount := iCount + tElement.Length - 1
  2512.                 iCount := iCount + tElement.Length
  2513.             else
  2514.             begin
  2515.                 //find in list and replace with tag
  2516.                 if (iStart + tElement.Length + 1) < Document.Length then
  2517.                     sResult := Document.GetTextRange(iStart, iStart + tElement.Length)
  2518.                 else
  2519.                     sResult := Document.GetTextRange(iStart, Document.Length);
  2520.  
  2521.                 if Length(Trim(sResult)) > 0 then
  2522.                 begin
  2523.                     Result := sResult;
  2524.                     iCount := Document.Length;
  2525.                 end
  2526.                 else
  2527.                     iCount := iCount + tElement.Length - 1;
  2528.             end;
  2529.         except
  2530.         end;
  2531.     end;
  2532. end;
  2533.  
  2534. function TfrmDoc.SelLength: LongInt;
  2535. var
  2536.     lStart, lEnd: Integer;
  2537. begin
  2538.     if bSetup then
  2539.     begin
  2540.         if rtfDoc <> nil then
  2541.         begin
  2542.             lStart := rtfDoc.SelectionStart;
  2543.             lEnd := rtfDoc.SelectionEnd;
  2544.             Result := max_(lStart, lEnd) - min_(lStart, lEnd);
  2545.         end
  2546.         else
  2547.             Result := 0;
  2548.     end
  2549.     else
  2550.         Result := 0;
  2551. end;
  2552.  
  2553. function TfrmDoc.Find(sString: String; iStart: Integer; bCase: Boolean; bWholeWord: Boolean): LongInt;
  2554. var
  2555.     sType: TSearchTypes;
  2556. begin
  2557.     sType := [];
  2558.     //forward, case sensitive, regular expression
  2559.     Result := -1;
  2560.     try
  2561.         FindReplace.rtfFind.Text := Document.Text;
  2562.         if bCase then
  2563.             sType := sType + [stMatchCase];
  2564.         if bWholeWord then
  2565.             sType := sType + [stWholeWord];
  2566.         Result := FindReplace.rtfFind.FindText(sString, iStart, Document.Length - iStart, sType);
  2567.     except
  2568.         //nada
  2569.     end;
  2570. end;
  2571.  
  2572. function TfrmDoc.GetSelText: String;
  2573. begin
  2574.   try
  2575.     Result := Document.GetTextRange(SelStart, SelEnd);
  2576.   except
  2577.   end;
  2578. end;
  2579.  
  2580. procedure TfrmDoc.SetSelText(sText: String);
  2581. var
  2582.     iStart: Integer;
  2583. begin
  2584.     iStart := SelStart;
  2585.     Document.ReplaceText(iStart, SelLength, sText);
  2586.     rtfDoc.SetSelection(iStart, iStart + Length(sText));
  2587.     rtfDoc.ScrollCaretToView;
  2588. end;
  2589.  
  2590. function TfrmDoc.GetDocText: String;
  2591. begin
  2592.     Result := Document.Text;
  2593. end;
  2594.  
  2595. procedure TfrmDoc.SetDocText(sText: String);
  2596. begin
  2597.     Document.ReplaceText(0, Document.Length, sText);
  2598. end;
  2599.  
  2600. function TfrmDoc.GetDocHead: String;
  2601. var
  2602.     iStart, iEnd: Integer;
  2603. begin
  2604.     if FindDocHead(iStart, iEnd) then
  2605.     begin
  2606.         iStart := iStart + Length('<HEAD>');
  2607.         Result := Document.GetTextRange(iStart, iEnd)
  2608.     end
  2609.     else
  2610.         Result := '';
  2611. end;
  2612.  
  2613. procedure TfrmDoc.SetDocHead(sText: String);
  2614. var
  2615.     iStart, iEnd: Integer;
  2616. begin
  2617.     if Length(sText) > 0 then
  2618.         if FindDocHead(iStart, iEnd) then
  2619.         begin
  2620.             iEnd := iEnd + Length('</HEAD>');
  2621.             Document.ReplaceText(iStart, (iEnd - iStart), sText);
  2622.         end;
  2623. end;
  2624.  
  2625. function TfrmDoc.FindDocHead(var iStart, iEnd: Integer): Boolean;
  2626. begin
  2627.     iStart := -1;
  2628.     iEnd := -1;
  2629.     iStart := Document.FindString(0, Document.Length - 1, '<HEAD>', True, False, False);
  2630.     if iStart > -1 then
  2631.     begin
  2632.         iEnd := Document.FindString(iStart, Document.Length - 1, '</HEAD>', True, False, False);
  2633.     end;
  2634.     Result := (iStart > -1) and (iEnd > -1);
  2635. end;
  2636.  
  2637. function TfrmDoc.GetTextRange(iStart, iLength: Integer): String;
  2638. begin
  2639.     Result := '';
  2640.     if (min_(iStart, iLength) > 0) and (max_(iStart, iLength) < Document.Length - 1) then
  2641.         Result := Document.GetTextRange(iStart, iLength);
  2642. end;
  2643.  
  2644. procedure TfrmDoc.InsertText(sText: String; iPos: LongInt);
  2645. begin
  2646.     Document.InsertText(sText, iPos);
  2647. end;
  2648.  
  2649. procedure TfrmDoc.rtfDocDragOver(Sender, Source: TObject; X, Y: Integer;
  2650.   State: TDragState; var Accept: Boolean);
  2651. {var
  2652.     iStart: Integer;}
  2653. begin
  2654.     if (Source is TPTShellList) then
  2655.         Accept := True
  2656.     else if (Source = MainForm.ptlstNSFaves) then
  2657.         Accept := True
  2658.     else if (Source = MainForm.ptlstIEFaves) then
  2659.         Accept := True
  2660.     else if (Source = MainForm.tvProjects) then
  2661.         Accept := tOptions.CanEdit(ExtractFileExt((MainForm.tvProjects.Selected as TTreeNode).Text))
  2662.     else if (Source = MainForm.lvInternetFiles) then
  2663.         Accept :=  tOptions.CanEdit(ExtractFileExt(MainForm.lvInternetFiles.Selected.Caption))
  2664.     else if (Source = MainForm.lvWSFiles) then
  2665.         Accept := True;
  2666. end;
  2667.  
  2668. procedure TfrmDoc.QuickLink(sFileName: String);
  2669. var
  2670.    sText: String;
  2671. begin
  2672.     sText := tOptions.TagCase('<A HREF="');
  2673.     sText := sText + FileToURL(AbsoluteToRelative(sDocFileName, sFileName));
  2674.     if SelLength > 0 then
  2675.         sText := sText + '">' + SelText + tOptions.TagCase('</A>')
  2676.     else
  2677.         sText := sText + '">' + ExtractFileName(sFileName) + tOptions.TagCase('</A>');
  2678.     AddText(sText, '', True);
  2679. end;
  2680.  
  2681. procedure TfrmDoc.QuickImage(sFileName: String);
  2682. var
  2683.     pmimgPreview: TPMultiImage;
  2684.     sText: String;
  2685.     c: TCursor;
  2686. begin
  2687.     c := Screen.Cursor;
  2688.     Screen.Cursor := crHourglass;
  2689.     pmimgPreview := TPMultiImage.Create(Self);
  2690.     pmimgPreview.Visible := False;
  2691.     pmimgPreview.Parent := Self;
  2692.     pmimgPreview.Stretch := True;
  2693.     try
  2694.         pmimgPreview.ImageName := sFileName;
  2695.  
  2696.         if SelLength = 0 then
  2697.         begin
  2698.             sText := tOptions.TagCase('<IMG SRC="') + FileToURL(AbsoluteToRelative(sDocFileName, sFileName)) + '"';
  2699.             try
  2700.                sText := sText + ' WIDTH="' + IntToStr(pmimgPreview.bWidth) + '"';
  2701.             except
  2702.             end;
  2703.             try
  2704.                sText := sText + ' HEIGHT="' + IntToStr(pmimgPreview.bHeight) + '"';
  2705.             except
  2706.             end;
  2707.             try
  2708.               sText := sText + ' BORDER="0"';
  2709.             except
  2710.             end;
  2711.             try
  2712.                sText := sText + ' ALT="' + ExtractFileName(sFileName) + ' - ' +  IntToStr(pmimgPreview.bSize)  + ' Bytes' + '"';
  2713.             except
  2714.             end;
  2715.             sText := sText + '>' + GetSelText;
  2716.         end
  2717.         else
  2718.         begin
  2719.             sText := tOptions.TagCase('<A HREF="');
  2720.             sText := sText + FileToURL(AbsoluteToRelative(sDocFileName, sFileName)) + '"';
  2721.             //sText := sText + '">' + SelText + '</A>';
  2722.             //sText := sText + ' HEIGHT="' + IntToStr(pmimgPreview.bHeight) + '"';
  2723.             //sText := sText + ' WIDTH="' + IntToStr(pmimgPreview.bWidth) + '"';
  2724.             //sText := sText + ' ALT="' + ExtractFileName(sFileName) + '"';
  2725.             sText := sText + '>' + SelText + tOptions.TagCase('</A>');
  2726.         end;
  2727.  
  2728.         AddText(sText, '', True);
  2729.     finally
  2730.         pmimgPreview.Free;
  2731.         Screen.Cursor := c;
  2732.     end;
  2733. end;
  2734.  
  2735. procedure TfrmDoc.rtfDocSelectionChanged(Sender: TObject; nStart,
  2736.   nEnd: Integer);
  2737. var
  2738.     iCol, iRow: Integer;
  2739. begin
  2740.     if bSetup then
  2741.     begin
  2742.         //iLastfind := SelStart;
  2743.         HideToolbarShit(True);
  2744.         rtfDoc.FindCoordinateFromPosition(nStart, iCol, iRow);
  2745.         SetCoords(iCol, iRow);
  2746.         FindReplace.SelChanged(nStart);
  2747.         //MainForm.propSheet.Position := nStart;
  2748.     end;
  2749. end;
  2750.  
  2751. procedure TfrmDoc.rtfDocDragDrop(Sender, Source: TObject; X, Y: Integer);
  2752. const
  2753.     MOUSEEVENTF_LEFTDOWN = $2;        //left button down
  2754.     MOUSEEVENTF_ABSOLUTE = $8000;    //absolute move
  2755.     MOUSEEVENTF_LEFTUP = $4;        //left button up
  2756. var
  2757.     ItemData: TPTShListData;
  2758.     sLink: String;
  2759.     //Info: TShellLinkInfo;
  2760.     tRegIni: TIniFile;
  2761.     iStart : Integer;
  2762.     iSelStart, iSelEnd : Integer;
  2763.     //sPathname : String;
  2764.     sImage : String;
  2765.     rectSelection : TGridRect;
  2766.     sDesc: TPTShListData;
  2767. begin
  2768.     if SelLength = 0 then
  2769.     begin
  2770.          iStart := rtfDoc.FindPositionFromPoint(X, Y);
  2771.          rtfDoc.SetSelection(iStart, iStart);
  2772.     end;
  2773.     if (Source = MainForm.ptList) then
  2774.     begin
  2775.         ItemData := (Source as TPTShellList).SelectedItem;
  2776.         if tOptions.IsImage(ItemData.PathName) then
  2777.         begin
  2778.             QuickImage(ItemData.PathName);
  2779.         end
  2780.         else //if tOptions.CanEdit(ExtractFileExt(ItemData.PathName)) then
  2781.         begin
  2782.             if tOptions.IsPreviewableImage(ItemData.PathName) then
  2783.             begin
  2784.                 ModalResult := MessageDlg(ExtractFileExt(ItemData.PathName) + ' files cannot be inserted into Hotdog. Do you wish to ' +
  2785.                 'convert this image to another file format? Selecting No will insert a link to this file.', mtConfirmation, [mbYes, mbNo, mbCancel],0);
  2786.                 if ModalResult = mrYes then
  2787.                 begin
  2788.                      sImage := PreviewImage(ItemData.PathName);
  2789.                      if tOptions.IsImage(sImage) then
  2790.                         QuickImage(sImage);
  2791.                 end
  2792.                 else if ModalResult = mrNo then
  2793.                         QuickLink(ItemData.PathName);
  2794.             end
  2795.             else
  2796.                 QuickLink(ItemData.PathName);
  2797.         end;
  2798.     end
  2799.     else if (Source = MainForm.lvWSFiles) and (MainForm.lvWSFiles.Selected <> Nil) then
  2800.     begin
  2801.         sDesc := TPTShListData(MainForm.lvWSFiles.Selected.Data);
  2802.         if sDesc <> nil then
  2803.         begin
  2804.             if tOptions.IsImage(sDesc.PathName) then
  2805.                 QuickImage(sDesc.PathName)
  2806.             else
  2807.                 QuickLink(sDesc.PathName);
  2808.         end;
  2809.     end
  2810.         //QuickLink((MainForm.lvProjects.Selected as TTreeNode).Text)
  2811.  
  2812.     else if (Source = MainForm.lvInternetFiles) and (MainForm.lvInternetFiles.Selected <> Nil) then
  2813.         QuickLink(MainForm.lvInternetFiles.Selected.Caption)
  2814.  
  2815.     else if (Source = MainForm.ptlstNSFaves) then
  2816.     begin
  2817.         //GetShellLinkInfo(MainForm.ptlstNSFaves.SelectedItem.Pathname, Info);
  2818.         sLink := ReadWholeFile(MainForm.ptlstNSFaves.SelectedItem.Pathname);
  2819.         DocFaveLink(Between(sLink, #13#10, #13#10), Copy(sLink, 0, Pos(#13#10, sLink) -1));
  2820.     end
  2821.     else if (Source = MainForm.ptlstIEFaves) then
  2822.     begin
  2823.         tRegIni := TIniFile.Create(MainForm.ptlstIEFaves.SelectedItem.Pathname);
  2824.         try
  2825.         begin
  2826.         { sample
  2827.         [InternetShortcut]
  2828.         URL=http://www.bitch.com/
  2829.         }
  2830.             sURL := tRegIni.ReadString('InternetShortcut', 'URL', '');
  2831.             if sURL <> '' then
  2832.                 DocFaveLink(sURL, MainForm.ptlstIEFaves.SelectedItem.Filename);
  2833.         end
  2834.         finally
  2835.             tRegIni.Free;
  2836.         end;
  2837.         //GetShellLinkInfo(MainForm.ptlstIEFaves.SelectedItem.Pathname, Info);
  2838.         //sURL := Info.Description;
  2839.         //DocFaveLink(sURL, MainForm.ptlstIEFaves.SelectedItem.Filename);
  2840.     end
  2841.     else if (Source = MainForm.treeMacro) then
  2842.     begin
  2843.          MainForm.treeMacroDblClick(Self);
  2844.     end
  2845.     else if (Source = MainForm.treeTags) then
  2846.     begin
  2847.         sURL := CreateTagsDropText(Source, SelText);
  2848.         AddText(sURL, '', True);
  2849.     end
  2850.     else if (Source = MainForm.lvExtChar) then
  2851.     begin
  2852.         if Pos('>', MainForm.lvExtChar.ItemFocused.SubItems[0]) = 0 then
  2853.             AddText(MainForm.lvExtChar.ItemFocused.SubItems[0] + ';', '', True)
  2854.         else
  2855.             AddText(MainForm.lvExtChar.ItemFocused.SubItems[0], '', True);
  2856.     end
  2857.     //ThumbNailButton made Modal so that other dialogs won't hide behind it.
  2858.     {else if ((Source as TControl).parent.classname = 'TThumbNailButton') then
  2859.     begin
  2860.         sPathName := ((Source as TControl).parent as TThumbNailButton).PathName;
  2861.         if tOptions.IsImage(sPathName) then
  2862.            QuickImage(((Source as TControl).parent as TThumbNailButton).PathName)
  2863.         else
  2864.         begin
  2865.            if MessageDlg(ExtractFileExt(sPathName) + ' files cannot be inserted into Hotdog. Do you wish to ' +
  2866.            'convert this image to another file format?', mtConfirmation, [mbYes, mbNo],0) = mrYes then
  2867.                 PreviewImage(sPathName);
  2868.         end;
  2869.     end}
  2870.     else if (Source = MainForm.strClipboard) then
  2871.     begin
  2872.          rectSelection := MainForm.strClipboard.Selection;
  2873.          if MainForm.strClipboard.Objects[rectSelection.TopLeft.X, rectSelection.TopLeft.Y] <> nil then
  2874.             //SelText := (MainForm.strClipboard.Objects[rectSelection.TopLeft.X, rectSelection.TopLeft.Y] as TClipboardString).sItem;
  2875.             AddText((MainForm.strClipboard.Objects[rectSelection.TopLeft.X, rectSelection.TopLeft.Y] as TClipboardString).sItem, '', True);
  2876.     end
  2877.     //Should leave this last because it is simply testing for TPanel
  2878.     else if (Source is TPanel) then
  2879.     begin
  2880.          if (Source as TPanel).Parent = MainForm.panColours then
  2881.             AddText((Source as TPanel).Hint, '', True);
  2882.     end;
  2883.     MainForm.SetFocus;
  2884.     SendMessage(Handle, WM_SETFOCUS, 0,0);
  2885.     rtfDoc.ScrollCaretToView;
  2886. end;
  2887.  
  2888. procedure TfrmDoc.DocFaveLink(sFileName, sDesc: String);
  2889. var
  2890.     sText: String;
  2891. begin
  2892.     sText := tOptions.TagCase('<A HREF="');
  2893.     sText := sText + FileToURL(AbsoluteToRelative(sDocFileName, sFileName));
  2894.     if SelLength > 0 then
  2895.         sText := sText + '">' + SelText + tOptions.TagCase('</A>')
  2896.     else
  2897.         sText := sText + '">' + Trim(StripFileExtensions(sDesc)) + tOptions.TagCase('</A>');
  2898.     //will replace Selected Text, or Insert Text if none selected
  2899.     AddText(sText, '', True);
  2900.     rtfDoc.SetFocus;
  2901. end;
  2902.  
  2903. (*
  2904. procedure TfrmDoc.AddToRecent;
  2905. begin
  2906.     AddToRecentFiles(sDocFileName, mnuFile, RecentFilesItemClick);
  2907.     MainForm.ReadRecent;
  2908. end;
  2909. *)
  2910.  
  2911. procedure TfrmDoc.DocHeading(iHeading: Integer);
  2912. var
  2913.    iStart: Integer;
  2914.    iEnd: Integer;
  2915.    sNew: String;
  2916. begin
  2917.     if iHeading = 0 then
  2918.     begin
  2919.         if SelLength > 0 then
  2920.         begin
  2921.             iStart := Pos('<h', LowerCase(SelText));
  2922.             if iStart > 0 then
  2923.             begin
  2924.                 sNew := Copy(SelText, iStart + 4, SelLength);
  2925.                 iEnd := Pos('</h', LowerCase(sNew));
  2926.                 if iEnd > 0 then
  2927.                     sNew := Copy(sNew, 0, iEnd - 1);
  2928.                 SelText := sNew;
  2929.             end;
  2930.         end;
  2931.     end
  2932.     else
  2933.         AddText(tOptions.TagCase('<H') + IntToStr(iHeading) + '>' + SelText, tOptions.TagCase('</H') + IntToStr(iHeading) + '>', False);
  2934. end;
  2935.  
  2936. procedure TfrmDoc.InsertTable;
  2937. begin
  2938.         try
  2939.            Screen.Cursor := crHourglass;
  2940.        Application.CreateForm(TfrmTableWizard, frmTableWizard);
  2941.         finally
  2942.            Screen.Cursor := crDefault;
  2943.         end;
  2944.     frmTableWizard.ShowModal;
  2945. end;
  2946.  
  2947. procedure TfrmDoc.QuickTable(sTableText: String);
  2948. begin
  2949.     SelText := sTableText;
  2950. end;
  2951.  
  2952. procedure TfrmDoc.DocFrameWizard;
  2953. begin
  2954.     try
  2955.        Screen.Cursor := crHourglass;
  2956.        Application.CreateForm(TfrmFrameWizard, frmFrameWizard);
  2957.     finally
  2958.        Screen.Cursor := crDefault;
  2959.     end;
  2960.     frmFrameWizard.ShowModal;
  2961.     if frmFrameWizard.ModalResult = mrOK then
  2962.     begin
  2963.        SelText := frmFrameWizard.sFrameText;
  2964.        if (Pos('<BODY', Uppercase(Text)) > 0) or (Pos('</BODY>', Uppercase(Text)) > 0) then
  2965.           frmFrameWizard.InsertNoFrames;
  2966.     end;
  2967.     frmFrameWizard.release;
  2968. end;
  2969.  
  2970. procedure TfrmDoc.HideToolbarShit(bOnlySelectionChanged : Boolean);
  2971. begin
  2972.     //Check available features
  2973.     { Standard }
  2974.     if rtfDoc <> nil then
  2975.     begin
  2976.         EnableToolbarButton(SAVE_BUTTON, (bDocDirty) or (Length(FileName) = 0));
  2977.         EnableToolbarButton(CUT_BUTTON, (rtfDoc.SelectionStart <> rtfDoc.SelectionEnd));
  2978.         EnableToolbarButton(COPY_BUTTON, (rtfDoc.SelectionStart <> rtfDoc.SelectionEnd));
  2979.  //       MainForm.buttUndo.Enabled := Document.CanUndo;
  2980.  //       MainForm.buttRedo.Enabled := Document.CanRedo;
  2981.         EnableToolbarButton(UNDO_BUTTON, Document.UndoManager.CanUndo);
  2982.         MainForm.buttUndoList.Enabled := Document.UndoManager.CanUndo;
  2983.         EnableToolbarButton(REDO_BUTTON, Document.UndoManager.CanRedo);
  2984.         MainForm.buttRedoList.Enabled := Document.UndoManager.CanUndo;
  2985.         EnableToolbarButton(PASTE_BUTTON, Clipboard.HasFormat(CF_TEXT));
  2986.         MainForm.DirtyBird(True);
  2987.         if not bOnlySelectionChanged then
  2988.             MainForm.HideShit;
  2989.     end;
  2990. end;
  2991.  
  2992. procedure TfrmDoc.MainViewRightClick(X, Y: Integer);
  2993. function ValidateSpellText(sCheckSpell:string):boolean;
  2994. var
  2995.     ipos: Integer;
  2996.     bIsWordGood: Boolean;
  2997. begin
  2998.     ipos:=1;
  2999.     bIsWordGood:=True;
  3000.     if Trim(sCheckSpell) = '' then
  3001.         bIsWordGood:=False;
  3002.     while (ipos <= length(sCheckSpell)) and (bIsWordGood = True) do
  3003.     begin
  3004.          if not((ord(sCheckSpell[ipos]) >=65) AND (ord(sCheckSpell[ipos]) <=90)
  3005.             or ((ord(sCheckSpell[ipos]) >=97) AND (ord(sCheckSpell[ipos]) <=122))) then
  3006.                 bIsWordGood:=False;
  3007.          ipos:=ipos+1;
  3008.     end;
  3009.     Result := bIsWordGood;
  3010. end;
  3011.  
  3012. { MainViewRightClick }
  3013. const
  3014.   maxSuggBfr = 1024;
  3015.   maxSuggestions = 16;
  3016. var
  3017.     { Evil Physicsboy Spellchecker }
  3018.     NewMenuItem: TMenuItem;
  3019.     //ImagePreviewItem : TMenuItem;
  3020.     wrd: array[0..SSCE_MAX_WORD_SZ] of SSCE_CHAR;
  3021.     replWrd: array[0..SSCE_MAX_WORD_SZ] of SSCE_CHAR;
  3022.     suggBfr: array[0..maxSuggBfr] of Char;
  3023.     scores: array[0..maxSuggestions] of S16;
  3024.     suggWord: string[SSCE_MAX_WORD_SZ];
  3025.     i{, n} : Integer; {Hint}
  3026.     scorePtr: PS16;
  3027.     result: S16;
  3028.     //sID: S16;
  3029.     sWord: String;
  3030.  
  3031.     { Other }
  3032.     tElement: Variant;
  3033.     iStart: Integer;
  3034.     iPos: Integer;
  3035.     P, Q: TPoint;
  3036.     sTag: String;
  3037.     sFile : String;
  3038.     //gutterItems : Array[0..2] of TMenuItem;
  3039.     //NumberItems : Array[0..4] of TMenuItem;
  3040.     //popGutter : TPopupMenu;
  3041. begin
  3042.     if rtfDoc.PointInGutter(X, Y) then
  3043.         DisplayGutterPopup(X,Y)
  3044.     else
  3045.     begin
  3046.        iPos := rtfDoc.FindPositionFromPoint(X, Y);
  3047.        popMainEdit.Visible := False;
  3048.        popEditColor.Visible := False;
  3049.        nMainEdit.Visible := False;
  3050.        popPSP.Visible := False;
  3051.        popMainPreview.Visible := False;
  3052.        popMainHREF.Visible := False;
  3053.        if iPos <> Document.Length then
  3054.        begin
  3055.            while popViewMain.Items[popViewMain.Items.Count-1].Name <> 'Poste_restante' do
  3056.            begin
  3057.                popViewMain.Items[popViewMain.Items.Count-1].Free;
  3058.            end;
  3059.            popViewMain.Items[popViewMain.Items.Count-1].Visible:=False;
  3060.  
  3061.            tElement := Document.GetElementAt(iPos, iStart);
  3062.            //Check if a colour is highlighted
  3063.            if (Copy(SelText,1,1) = '#') and (Length(SelText) = 7) then
  3064.            begin
  3065.                 popEditColor.Caption := 'Edit Color';
  3066.                 popEditColor.Visible := True;
  3067.                 nMainEdit.Visible := True;
  3068.            end;
  3069.            if tElement.Type = HTMLSYNTAXELEMENT_TEXT then
  3070.            begin
  3071.                //sID := SSCE_OpenSession;
  3072.                //sID := SSCE_GetSid;
  3073.                if sID > 0 then
  3074.                begin
  3075.                    //function to parse for spaces around current spot
  3076.                    //sWord := GetWord(iPos, iStart, iStart + tElement.Length);
  3077.                    sWord := GetWordAtPos(iPos, iSpellStart, iSpellEnd);
  3078.                    if ValidateSpellText(sWord) then
  3079.                    begin
  3080.                        if (Trim(sWord) <> '') and (slSpellAddList.IndexOf(Trim(sWord)) = -1) then    //not almost in dictionary
  3081.                        begin
  3082.                            StrPCopy(wrd, sWord);
  3083.                            result := SSCE_CheckWord(sID, 0, wrd, replWrd, Sizeof(replWrd));
  3084.                            if result<0 then
  3085.                               // showmessage('Spell Checker Error')
  3086.                            else
  3087.                            begin
  3088.                               if ((result and SSCE_MISSPELLED_WORD_RSLT) <> 0) then
  3089.                               begin
  3090.                                   scorePtr := @scores[0];
  3091.                                   result := SSCE_Suggest(sID, wrd, 3, suggBfr, maxSuggBfr, scorePtr,maxSuggestions);
  3092.                                   if (result < 0) then
  3093.                                   begin
  3094.                                       //ShowMessage('Spell Checker Suggestion Error: ' + IntToStr(result));
  3095.                                   end
  3096.                                   else
  3097.                                   begin
  3098.                                       {The set of suggestions is returned as a collection of words,}
  3099.                                       {separated by nulls. The last word is marked by a double null.}
  3100.                                       i := 0;
  3101.                                       //n := 0; {Hint}
  3102.                                       popViewMain.Items[popViewMain.Items.Count-1].Visible:=True;
  3103.                                       while (suggBfr[i] <> #0) do
  3104.                                       begin
  3105.                                           suggWord := '';
  3106.                                           while (suggBfr[i] <> #0) do
  3107.                                           begin
  3108.                                               suggWord := suggWord + suggBfr[i];
  3109.                                               i := i + 1;
  3110.                                           end;
  3111.                                           NewMenuItem := TMenuItem.Create(popViewMain);
  3112.                                           NewMenuItem.OnClick := CorrectWord;
  3113.                                           NewMenuItem.Caption := suggWord;
  3114.                                           popViewMain.Items.Insert(popViewMain.Items.Count, NewMenuItem);
  3115.                                           i := i + 1;
  3116.                                           //n := n + 1; {Hint}
  3117.                                       end;
  3118.                                   end
  3119.                               end;
  3120.                               { - don't worry about this code - its okay to leave it out I think.
  3121.                               I'll check it later:
  3122.                               if ((result and SSCE_SUGGEST_WORD_RSLT) <> 0) then
  3123.                               begin
  3124.                                   showmessage('Suggest replacing ' + Edit1.Text +' with ' + StrPas(replWrd));
  3125.                               end;
  3126.                               }
  3127.                            end;
  3128.                        end;
  3129.                    end;
  3130.                    //SSCE_CloseSession(sID);
  3131.                end;
  3132.            end
  3133.            {else if (tElement.Type = HTMLSYNTAXELEMENT_COLORVALUE) then
  3134.            begin
  3135.                popMainEdit.Caption := 'Edit Color';
  3136.                popMainEdit.Visible := True;
  3137.                nMainEdit.Visible := True;
  3138.                //Set Right Click Values to Element bounds
  3139.                tCurrentElement.iStart := iStart;
  3140.                tCurrentElement.iLength := iStart + tElement.Length;
  3141.                tCurrentElement.iType := tElement.Type;
  3142.                tCurrentElement.sTagName := 'Edit Color';
  3143.            end  //Can't do this yet - Kin               }
  3144.            else if tElement.Type = HTMLSYNTAXELEMENT_COMMENT then
  3145.            begin
  3146.                //comment
  3147.                popMainEdit.Caption := 'Remove Comment Tags';
  3148.                popMainEdit.Visible := True;
  3149.                nMainEdit.Visible := True;
  3150.                //Set Right Click Values to Element bounds
  3151.                tCurrentElement.iStart := iStart;
  3152.                tCurrentElement.iLength := iStart + tElement.Length;
  3153.                tCurrentElement.iType := tElement.Type;
  3154.                tCurrentElement.sTagName := 'Remove Comment Tags'; 
  3155.            end
  3156.            {else if tElement.Type = HTMLSYNTAXELEMENT_ERROR then
  3157.            begin
  3158.                //error
  3159.                ShowMessage('Error');
  3160.            end}
  3161.            else if ((tElement.Type = HTMLSYNTAXELEMENT_TAG) or (tElement.Type = HTMLSYNTAXELEMENT_ERROR)) then
  3162.            begin
  3163.                //tag
  3164.                sTag := Document.GetTextRange(iStart, iStart + tElement.Length);
  3165.                if IsTagEditable(sTag) then
  3166.                begin
  3167.                    tCurrentElement.sTagName := GetTagName(sTag);
  3168.                    popMainEdit.Caption := 'Edit ' + tCurrentElement.sTagName + ' Tag';
  3169.                    popMainEdit.Visible := True;
  3170.                    nMainEdit.Visible := True;
  3171.                    //Set Right Click Values to Element bounds
  3172.                    tCurrentElement.iStart := iStart;
  3173.                    tCurrentElement.iLength := iStart + tElement.Length;
  3174.                    tCurrentElement.iType := tElement.Type;
  3175.                    If tCurrentElement.sTagName = 'Image' then
  3176.                    begin
  3177.                       popMainPreview.Visible := True;
  3178.                       //if tReg.OpenTo(INI_PARTNER_PSP, False) then
  3179.                       {$IFNDEF HOTDOG_STAND_ALONE}
  3180.                           popPSP.Visible := True;
  3181.                       {$ENDIF}
  3182.                   end;
  3183.                end;
  3184.                if Length(GetTag(sTag, '<a href', '>')) > 0 then
  3185.                begin
  3186.                     sTag := ReplaceString(sTag, '<a href =', '<a href=');
  3187.                     sTag := ReplaceString(sTag, '<a href= ', '<a href=');
  3188.                     sFile := URLToFile(GetAttribute(sTag, 'href'));
  3189.                     if Pos('#', sFile) > 0 then
  3190.                        sFile := Copy(sFile, 0, Pos('#',sFile)-1);
  3191.  
  3192.                     //if (not(FileExists(sFile))) and (FileName <> '') then
  3193.                     sFile := RelativeToAbsolute(Filename, sFile);
  3194.                     if FileExists(sFile) then
  3195.                     begin
  3196.                        popMainHREF.Visible := True;
  3197.                        popMainHREF.Hint := sFile;
  3198.                     end;
  3199.                end;
  3200.            end
  3201.            else
  3202.            begin
  3203.                //fuck knows....
  3204.                tCurrentElement.iType := HTMLSYNTAXELEMENT_INVALID;
  3205.            end;
  3206.        end;
  3207.  
  3208.        P := Point(X, Y);
  3209.        Q := rtfDoc.ClientToScreen(P);
  3210.        popViewMain.PopUp(Q.X, Q.Y);
  3211.     end;
  3212. end;
  3213.  
  3214. procedure TfrmDoc.CorrectWord(Sender: TObject);
  3215. begin
  3216.     Document.ReplaceText(iSpellStart, iSpellEnd - iSpellStart, TMenuItem(Sender).Caption);
  3217.     while popViewMain.Items[popViewMain.Items.Count-1].Name <> 'Poste_restante' do
  3218.     begin
  3219.         popViewMain.Items.Remove(popViewMain.Items[popViewMain.Items.Count-1]);
  3220.         popViewMain.Items[popViewMain.Items.Count-1].Free;
  3221.     end;
  3222.     popViewMain.Items[popViewMain.Items.Count-1].Visible:=False;
  3223. end;
  3224.  
  3225.  
  3226. procedure TfrmDoc.SetCursorPos(iPos: Integer);
  3227. begin
  3228.     //rtfDoc.SelectionStart := iPos;
  3229.     //rtfDoc.SelectionEnd := iPos;
  3230.     rtfDoc.SetSelection(iPos, iPos);
  3231. end;
  3232.  
  3233. procedure TfrmDoc.SetSelection(iStart, iLength: Integer);
  3234. begin
  3235.     rtfDoc.SetSelection(iStart, iStart + iLength);
  3236.     rtfDoc.ScrollCaretToView;
  3237. end;
  3238.  
  3239. procedure TfrmDoc.DocDelete;
  3240. //cunt
  3241. begin
  3242.     if SelLength > 0 then
  3243.         SelText := '';
  3244. end;
  3245.  
  3246. procedure TfrmDoc.popMainEditClick(Sender: TObject);
  3247. begin
  3248.     DocEditTag;
  3249. end;
  3250.  
  3251. procedure TfrmDoc.DocEditTag;
  3252. begin
  3253.  
  3254.     rtfDoc.SetSelection(tCurrentElement.iStart, tCurrentElement.iLength);
  3255.  
  3256.     if tCurrentElement.sTagName = 'Image' then
  3257.         InsertImage
  3258.     else if tCurrentElement.sTagName = 'Hypertext Link' then
  3259.         InsertLink(insLink)
  3260.     else if tCurrentElement.sTagName = 'Email Link' then
  3261.         InsertLink(insEmail)
  3262.     else if tCurrentElement.sTagName = 'FTP Link' then
  3263.         InsertLink(insFTP)
  3264.     else if tCurrentElement.sTagName = 'News Link' then
  3265.         InsertLink(insNews)
  3266.     else if tCurrentElement.sTagName = 'Line' then
  3267.         InsertLine
  3268.     else if tCurrentElement.sTagName = 'Table' then
  3269.         InsertTable
  3270.     else if tCurrentElement.sTagName = 'Font' then
  3271.         DocFont(True)
  3272.     else if tCurrentElement.sTagName = 'Remove Comment Tags' then
  3273.         DocComment 
  3274.     else if Pos('List', tCurrentElement.sTagName) > 0 then
  3275.         InsertList
  3276.     else if Pos('Font', tCurrentElement.sTagName) > 0 then
  3277.         InsertList
  3278.     else if tCurrentElement.sTagName = 'Body' then
  3279.     begin
  3280.         DocProperties;
  3281.     end
  3282.     {else if tCurrentElement.sTagName = 'Edit Color' then
  3283.     begin
  3284.         ShowMessage('Edit Color');//DocColor;
  3285.     end //can't do this yet - kin}
  3286.     else if tCurrentElement.sTagName = 'Paragraph' then
  3287.         //todo DocPara;
  3288. end;
  3289.  
  3290.  
  3291. function TfrmDoc.CheckDirty: Boolean;
  3292. begin
  3293.     Result := bDocDirty;
  3294. end;
  3295.  
  3296. function TfrmDoc.GetElementAt(iPosition: Integer; var iStart: Integer; var sElement: String): Variant;
  3297. (*
  3298.     Returns the HTML Element at iPosition in the document.
  3299.     iStart will be set to the starting position of the element.
  3300.     sElement will be filled with the Element.
  3301. *)
  3302. var
  3303.     sResult: Variant;
  3304. begin
  3305.     sResult := Document.GetElementAt(iPosition, iStart);
  3306.     sElement := Document.GetTextRange(iStart, iStart + sResult.Length);
  3307.  
  3308.     //Return Data
  3309.     Result := sResult;
  3310. end;
  3311.  
  3312. procedure TfrmDoc.lmdDocMRUClick(Sender: TObject; const aValue: string;
  3313.   var Remove: Boolean);
  3314. begin
  3315.     //MainForm.lmdMRU.CheckSharedFile(aValue);
  3316. end;
  3317.  
  3318. procedure TfrmDoc.rtfDocMouseDown(Sender: TObject; Button: TMouseButton;
  3319.   Shift: TShiftState; X, Y: Integer);
  3320. begin
  3321.     BringToFront;
  3322. end;
  3323.  
  3324. function TfrmDoc.CreateTagsDropText(Source: TObject; sHighlighted : String):string;
  3325. var
  3326.     sTemp,sAttrTemp:string;
  3327.     vElementLookup,vAttrLookup:variant;
  3328.     i:integer;
  3329.     iAttrCount:integer;
  3330. begin
  3331.      sTemp:=(source as TCustomTreeView).selected.text;
  3332.      if sTemp[1]='<' then
  3333.      begin
  3334.           sTemp:='<'+chopbefore(chopafter((source as TCustomTreeView).selected.text,'<'),'>');
  3335.           if (source as TCustomTreeView).selected.expanded then
  3336.           begin
  3337.                vElementLookup := MainForm.vTagsLookup.Lookup(chopbefore(chopafter((source as TCustomTreeView).selected.text,'<'),'>'));
  3338.                iAttrCount:=vElementLookup.ElementCount;
  3339.                if iAttrCount>0 then
  3340.                begin
  3341.                     for i:=0 to iAttrCount-1 do
  3342.                     begin
  3343.                          sAttrTemp:=vElementLookup.ElementName(i);
  3344.                          sTemp:=sTemp+' '+sAttrTemp; // add attr name
  3345.  
  3346.                          vAttrLookup:=vElementLookup.Lookup(sAttrTemp); // get attr type
  3347.                          case vAttrLookup.ValueType of
  3348.                            1:  sTemp:=sTemp+'=';
  3349.                            2:  sTemp:=sTemp+'=""';
  3350.                            3:  sTemp:=sTemp+'=';
  3351.                            4:  sTemp:=sTemp+'=""';
  3352.                            5:  sTemp:=sTemp+'="#"';
  3353.                          end;
  3354.                     end;
  3355.                end;
  3356.           end;
  3357.           sTemp:=sTemp+'>' + sHighlighted;
  3358.           vElementLookup:= MainForm.vTagsPairLookup.lookup(chopbefore(chopafter((source as TCustomTreeView).selected.text,'<'),'>'));
  3359.           try
  3360.              if vElementLookup.AlwaysRequired then
  3361.                 sTemp:=sTemp+'</'+chopbefore(chopafter((source as TCustomTreeView).selected.text,'<'),'>')+'>';
  3362.           except
  3363.           end;
  3364.      end;
  3365.      result:=sTemp;
  3366. end;
  3367.  
  3368. procedure TfrmDoc.StripTags;
  3369. //procedure TfrmDoc.DocExportToText;
  3370.  
  3371. (* Local Procedures *)
  3372.   function GetFileName: String;
  3373.   var
  3374.       tDlgSave: TFileDialog;
  3375.   begin
  3376.       tDlgSave := TFileDialog.Create(Self);
  3377.       try
  3378.       begin
  3379.           //tdlgSave.UseWinDialog := not(tOptions.UseCustomFileDialog);
  3380.           tdlgSave.OpenFile := False;
  3381.           tDlgSave.InitialDir := tOptions.DocumentDirectory;
  3382.           tDlgSave.DefaultExt := tOptions.DefaultDocExtension;
  3383.           tDlgSave.WinOptions := [ofOverwritePrompt, ofHideReadOnly];
  3384.           tDlgSave.CustomOptions := [ptofOverwritePrompt, ptofHideReadOnly];
  3385.           tDlgSave.Filter := 'Text Files (*.txt)|*.txt|All Files (*.*)|*.*';
  3386.           if tDlgSave.Execute then
  3387.           begin
  3388.               Result := tDlgSave.FileName;
  3389.           end
  3390.           else
  3391.               Result := '';
  3392.       end
  3393.       finally
  3394.           tDlgSave.Free;
  3395.       end;
  3396.   end;
  3397.  
  3398. (* DocExportToText *)
  3399. var
  3400.     sTag: String;
  3401.     iStart: integer;
  3402. begin
  3403.     iStart := 0;
  3404.     repeat
  3405.         sTag := GetNextTag(iStart);
  3406.         if Length(sTag) > 0 then
  3407.         begin
  3408.             Document.ReplaceText(iStart, Length(sTag), '');
  3409.         end;
  3410.     until Length(sTag) = 0;
  3411. end;
  3412.  
  3413. function TfrmDoc.ReplaceAll(sFind, sReplace: String): Integer;
  3414. var
  3415.    iLastPos: Integer;
  3416.    iPos: Integer;
  3417. begin
  3418.     Result := 0;
  3419.     iLastPos := 0;
  3420.     iPos := 0;  //MrKistic - 15 September 1997
  3421.     while (iLastPos < Document.Length - 1) and (iPos <> -1) do
  3422.     begin
  3423.         iPos := Find(sFind, iLastPos, True, False);
  3424.         if iPos > -1 then
  3425.         begin
  3426.             //string found
  3427.             begin
  3428.                 Document.ReplaceText(iPos, Length(sFind), sReplace);
  3429.                 iLastPos := iPos + Length(sReplace);
  3430.                 Inc(Result);
  3431.             end;
  3432.         end;
  3433.     end;
  3434.  
  3435. end;
  3436.  
  3437. procedure TfrmDoc.DocPublishToFileOrScreen;
  3438. var
  3439.     iChanges : Integer;
  3440.     sPublishDir : String;
  3441. begin
  3442.     if tOptions.PublishToDir then
  3443.     begin
  3444.         iChanges := PublishDocumentInAShouseyManner;
  3445.         sPublishDir := FilePath(tOptions.PublishDirectory, ExtractFileName(sDocFileName));
  3446.         if iChanges > -1 then
  3447.             MessageDlg(Format('The HotDog Publisher has finished with this document. %d changes were made to %s .', [iChanges, sPublishDir]),
  3448.                 mtInformation, [mbOK], 0);
  3449.     end
  3450.     else
  3451.     begin
  3452.         if tOptions.ShowPublishMsg then
  3453.         begin
  3454.             Application.CreateForm(TfrmPublishMsg,frmPublishMsg);
  3455.             frmPublishMsg.ShowModal;
  3456.             if frmPublishMsg.ModalResult = mrOk then
  3457.                 DocPublish;
  3458.             frmPublishMsg.Free;
  3459.         end
  3460.         else
  3461.             DocPublish;
  3462.     end;
  3463. end;
  3464.  
  3465. procedure TfrmDoc.DocPublish;
  3466. { DocPublish }
  3467. var
  3468.     iCount, iChanges: Integer;
  3469.     //iLastPos : Integer;
  3470.     sFind, sReplace: String;
  3471.     slItems: TStringList;
  3472. begin
  3473.     Status('Publishing document...');
  3474.     iChanges := 0;
  3475.     begin
  3476.         slItems := TStringList.Create;
  3477.         try
  3478.             tOptions.ReadPubReplaceStrings(slItems);
  3479.             for iCount := 0 to slItems.Count - 1 do
  3480.             begin
  3481.                 sFind := ChopBefore(slItems.Strings[iCount], '=');
  3482.                 sReplace := slItems.Values[sFind];
  3483.                 iChanges := iChanges + ReplaceAll(sFind, sReplace);
  3484.             end;
  3485.             if tOptions.PublishTagCase > 0 then
  3486.             begin
  3487.                 iChanges := iChanges + DocConvertTagCase(True, True);
  3488.             end;
  3489.             if tOptions.PublishExtChar then
  3490.             begin
  3491.                 iChanges := iChanges + DocConvertExtChar;
  3492.             end;
  3493.             if tOptions.PublishCR then
  3494.             begin
  3495.                 iChanges := iChanges + DocConvertCR(False);
  3496.             end;
  3497.             if tOptions.PublishSlash then
  3498.             begin
  3499.                  iChanges := iChanges + DocConvertSlash;
  3500.             end;
  3501.             SetFileFormat(DocEOLType(tOptions.PublishFileFormat));
  3502.             iChanges := iChanges + PublishFields;
  3503.             //WriteWholeFile(sPubFile, sDocument);
  3504.         finally
  3505.             slItems.Free;
  3506.         end;
  3507.     end;
  3508.     MessageDlg(Format('The HotDog Publisher has finished with this document. %d changes were made.', [iChanges]),
  3509.                 mtInformation, [mbOK], 0);
  3510.     Status('');
  3511. end;
  3512.  
  3513. {-= MrKistic - 19 November 1997 =-}
  3514. function TfrmDoc.PublishDocumentInAShouseyManner: Integer;
  3515.  
  3516. { Local Procedure }
  3517. function ShitReplaceAll(var sText: String; sFind, sReplace: String): Integer;
  3518. var
  3519.     iLastPos: Integer;
  3520.     iPos: Integer;
  3521. begin
  3522.     Result := 0;
  3523.     iLastPos := 0;
  3524.     iPos := -1;
  3525.     while (iLastPos < Length(sText)) and (iPos <> 0) do
  3526.     begin
  3527.         iPos := PosIn(sFind, sText, iLastPos);
  3528.         if iPos > 0 then
  3529.         begin
  3530.             begin
  3531.                 Delete(sText, iPos, Length(sFind));
  3532.                 Insert(sReplace, sText, iPos);
  3533.                 iLastPos := iPos + Length(sReplace);
  3534.                 Inc(Result);
  3535.             end;
  3536.         end;
  3537.     end;
  3538. end;
  3539.  
  3540. function ShitFindTagInList(sChar: String): String;
  3541. var
  3542.     iCount: Integer;
  3543. begin
  3544.     iCount := 0;
  3545.     Result := '';
  3546.     //-- Sav 23-03-97
  3547.     while iCount <= High(ExtendedChars) do
  3548.     //while iCount <= MainForm.lvExtChar.Items.Count - 1 do
  3549.     begin
  3550.         if sChar = ExtendedChars[iCount][0] then
  3551.         //if sChar = MainForm.lvExtChar.Items.Item[iCount].Caption then
  3552.         begin
  3553.              if Pos('>', ExtendedChars[iCount][1]) = 0 then
  3554.              //if Pos('>', MainForm.lvExtChar.Items.Item[iCount].SubItems[0]) = 0 then
  3555.                 Result := ExtendedChars[iCount][1] + ';'
  3556.                 //Result := MainForm.lvExtChar.Items.Item[iCount].SubItems[0] + ';'
  3557.              else
  3558.                 Result := ExtendedChars[iCount][1];
  3559.                 //Result := MainForm.lvExtChar.Items.Item[iCount].SubItems[0];
  3560.         end;
  3561.         Inc(iCount);
  3562.     end;
  3563. end;
  3564.  
  3565. function ShitConvertExtChar(ShitDocument: Variant): Integer;
  3566. var
  3567.     sChar, sNewTag: String;
  3568.     iCount, iStart: Integer;
  3569.     tElement: Variant;
  3570.     iChanges: Integer;
  3571. begin
  3572.     iChanges := 0;
  3573.     iCount := 0;
  3574.     while iCount < ShitDocument.Length -1 do
  3575.     begin
  3576.         try
  3577.             sChar := ShitDocument.GetTextRange(iCount, iCount + 1);
  3578.             sChar := Trim(sChar);
  3579.             if Length(sChar) > 0 then
  3580.             begin
  3581.                 tElement := ShitDocument.GetElementAt(iCount, iStart);
  3582.                 if tElement.Type <> HTMLSYNTAXELEMENT_TEXT then
  3583.                     iCount := iCount + tElement.Length - 1
  3584.                 else if (Ord(sChar[1]) > 122) or (sChar = '>') or
  3585.                    (sChar = '<') or (sChar='&') or
  3586.                    (sChar = '"') then
  3587.                 begin
  3588.                     //find in list and replace with tag
  3589.                     sNewTag := ShitFindTagInList(sChar);
  3590.                     if sNewTag <> '' then
  3591.                     begin
  3592.                         ShitDocument.ReplaceText(iCount, Length(sChar), sNewTag);
  3593.                         iCount := iCount + Length(sNewTag) -1;
  3594.                         Inc(iChanges);
  3595.                     end;
  3596.                 end;
  3597.             end;
  3598.             Inc(iCount);
  3599.         except
  3600.             //nada
  3601.         end;
  3602.     end;
  3603.     Result := iChanges;
  3604. end;
  3605.  
  3606. { PublishDocumentInAShouseyManner }
  3607. var
  3608.     iCount, iChanges: Integer;
  3609.     //iPos: Integer;
  3610.     sFind, sReplace: String;
  3611.     sDocument: String;
  3612.     slItems: TStringList;
  3613.     bContinue: Boolean;
  3614.     OleSysError: EOleSysError;
  3615.     OleException: EOleException;
  3616.     sPubFile: String;
  3617.     ShitDocument: Variant;
  3618. begin
  3619.     if Trim(sDocFileName) = '' then
  3620.     begin
  3621.         if MessageDlg('This document must be saved before you can publish to a directory.', mtInformation, [mbOk,mbCancel],0) = mrOK then
  3622.             Save;
  3623.     end;
  3624.     if Trim(sDocFileName) = '' then
  3625.     begin
  3626.         Result := -1;
  3627.         exit;
  3628.     end;
  3629.     {$I+}
  3630.     if Not DirectoryExists(tOptions.PublishDirectory) then
  3631.         mkDir(tOptions.PublishDirectory);
  3632.     {$I-}
  3633.     sPubFile := FilePath(tOptions.PublishDirectory, ExtractFileName(sDocFileName));
  3634.     sDocument := Document.Text;
  3635.     WriteWholeFile(sPubFile, sDocument);
  3636.     try
  3637.         ShitDocument := CreateOLEObject('Sausage.HTMLTextDocument.2');
  3638.         ShitDocument.SetSyntaxManager(SyntaxManager);
  3639.         ShitDocument.Reparse;
  3640.         //FTPStatus('Converting Extended Characters...');
  3641.         while ShitDocument.Formatting do
  3642.               Application.ProcessMessages;
  3643.         bContinue := True;
  3644.     except
  3645.         on e: Exception do
  3646.         begin
  3647.             //if DEBUG_FLAG then
  3648.             begin
  3649.                 if e is EOleException then
  3650.                 begin
  3651.                     OleException := (e as EOleException);
  3652.                     if DEBUG_FLAG then
  3653.                         ShowMessage(OleException.Message);
  3654.                 end
  3655.                 else if e is EOleSysError then
  3656.                 begin
  3657.                     OleSysError := (e as EOleSysError);
  3658.                     if DWord(OleSysError.ErrorCode) = CO_E_CLASSSTRING then //-- Sav D4
  3659.                     begin
  3660.                         if DEBUG_FLAG then
  3661.                             ShowMessage('Invalid class string : The file "HTMLDocumentSvr.dll" has not been registered correctly.');
  3662.                     end
  3663.                     else if DWord(OleSysError.ErrorCode) = REGDB_E_CLASSNOTREG then //-- Sav D4
  3664.                     begin
  3665.                         if DEBUG_FLAG then
  3666.                             ShowMessage('Class not registered : The file "HTMLDocumentSvr.dll" has not been registered correctly.');
  3667.                     end
  3668.                     else if OleSysError.ErrorCode = ERROR_DLL_NOT_FOUND then
  3669.                     begin
  3670.                         if DEBUG_FLAG then
  3671.                             ShowMessage('DLL not found : The file "HTMLDocumentSvr.dll" has been registered but could not be loaded correctly.');
  3672.                     end
  3673.                     else
  3674.                         if DEBUG_FLAG then
  3675.                             ShowMessage(OleSysError.Message);
  3676.                 end
  3677.                 else
  3678.                     if DEBUG_FLAG then
  3679.                         ShowMessage(e.message);
  3680.             end;
  3681.             bContinue := False;
  3682.         end;
  3683.     end;
  3684.  
  3685.     iChanges := 0;
  3686.     if bContinue then
  3687.     begin
  3688.         try
  3689.             ShitDocument.LoadFromFile(sPubFile);
  3690.             if tOptions.PublishExtChar then
  3691.             begin
  3692.                 iChanges := ShitConvertExtChar(ShitDocument);
  3693.             end;
  3694.             if tOptions.PublishTagCase = 1 then
  3695.                iChanges := iChanges + ShitDocument.MakeAllNameUpper
  3696.             else if tOptions.PublishTagCase = 2 then
  3697.                iChanges := iChanges + ShitDocument.MakeAllNameLower;
  3698.             ShitDocument.EOLType := DocEOLType(tOptions.PublishFileFormat);
  3699.             //-- Sav Make sure all the publish fields are processed.
  3700.             ShitDocument.Text := PublishText(ShitDocument.Text, 'PUBLISH', sPubFile, iChanges);
  3701.             ShitDocument.SaveToFile(sPubFile);
  3702.         except
  3703.             //nada
  3704.         end;
  3705.     end;
  3706.  
  3707.     sDocument := ReadWholeFile(sPubFile);
  3708.     if Length(sDocument) > 0 then
  3709.     begin
  3710.         slItems := TStringList.Create;
  3711.         try
  3712.             tOptions.ReadPubReplaceStrings(slItems);
  3713.             for iCount := 0 to slItems.Count - 1 do
  3714.             begin
  3715.                 sFind := ChopBefore(slItems.Strings[iCount], '=');
  3716.                 sReplace := slItems.Values[sFind];
  3717.                 iChanges := iChanges + ShitReplaceAll(sDocument, sFind, sReplace);
  3718.             end;
  3719.             if tOptions.PublishCR then
  3720.             begin
  3721.                 iChanges := iChanges + ShitReplaceAll(sDocument, #13#10, '');
  3722.             end;
  3723.             if tOptions.PublishSlash then
  3724.             begin
  3725.                  iChanges := iChanges + ShitReplaceAll(sDocument, '\', '/');
  3726.             end;
  3727.             WriteWholeFile(sPubFile, sDocument);
  3728.         finally
  3729.             slItems.Free;
  3730.         end;
  3731.     end;
  3732.     Result := iChanges;
  3733.     if sDocFilename = sPubFile then
  3734.         Text :=  sDocument;
  3735. end;
  3736.  
  3737. function TfrmDoc.DocConvertSlash: Integer;
  3738. begin
  3739.     Result := ReplaceAll('\', '/');
  3740. end;
  3741.  
  3742. function TfrmDoc.DocConvertCR(bSelText : Boolean): Integer;
  3743. begin
  3744.      Result := 0;
  3745.      if bSelText then
  3746.         SelText := ReplaceString(SelText, #13#10, '')
  3747.      else
  3748.     Result := ReplaceAll(#13#10, '');
  3749. end;
  3750.  
  3751. function TfrmDoc.DocConvertExtChar: Integer;
  3752.  
  3753. { Local }
  3754. function FindTagInList(sChar: String): String;
  3755. var
  3756.     iCount: Integer;
  3757. begin
  3758.     iCount := 0;
  3759.     Result := '';
  3760.     //--Sav 23-03-97
  3761.     while iCount <= High(ExtendedChars) do
  3762.     //while iCount <= MainForm.lvExtChar.Items.Count - 1 do
  3763.     begin
  3764.         if sChar = ExtendedChars[iCount][0] then
  3765.         //if sChar = MainForm.lvExtChar.Items.Item[iCount].Caption then
  3766.         begin
  3767.              if Pos('>', ExtendedChars[iCount][1]) = 0 then
  3768.              //if Pos('>', MainForm.lvExtChar.Items.Item[iCount].SubItems[0]) = 0 then
  3769.                 Result := ExtendedChars[iCount][1] + ';'
  3770.                 //Result := MainForm.lvExtChar.Items.Item[iCount].SubItems[0] + ';'
  3771.              else
  3772.                 Result := ExtendedChars[iCount][1];
  3773.                 //Result := MainForm.lvExtChar.Items.Item[iCount].SubItems[0];
  3774.         end;
  3775.         Inc(iCount);
  3776.     end;
  3777. end;
  3778.  
  3779. function FindExistingTag(sTag: String): Boolean;
  3780. var
  3781.     iCount: Integer;
  3782. begin
  3783.     iCount := 0;
  3784.     Result := False;
  3785.     sTag := Trim(sTag);
  3786.     if (Copy(sTag, 1, 2) = '&#') and (Copy(sTag, 6, 1) = ';') then
  3787.         Result := True
  3788.     else
  3789.     begin
  3790.         //-- Sav 23-03-97
  3791.         sTag := Copy(sTag, 1, Length(sTag) - 1);
  3792.         while iCount <= High(ExtendedChars) do
  3793.         //while iCount <= MainForm.lvExtChar.Items.Count - 1 do
  3794.         begin
  3795.             if sTag = ExtendedChars[iCount][1] then
  3796.             //if sTag = MainForm.lvExtChar.Items.Item[iCount].SubItems[0] then
  3797.                 Result := True;
  3798.             Inc(iCount);
  3799.         end;
  3800.     end;
  3801. end;
  3802.  
  3803. function GetWord(iPos, iEnd: Integer): String;
  3804. var
  3805.     sChar: String;
  3806. begin
  3807.     Result := '';
  3808.     while iPos < iEnd do
  3809.     begin
  3810.         sChar := Document.GetTextRange(iPos, iPos + 1);
  3811.         Result := Result + sChar;
  3812.         if (sChar = ';') or (sChar = ' ') then
  3813.             iPos := iEnd
  3814.         else
  3815.             Inc(iPos);
  3816.     end;
  3817. end;
  3818.  
  3819. function GetAltWord(sAltText:string;iPos:integer): String; (*mg261196*)
  3820. var
  3821.     sChar: String;
  3822.     iEnd:integer;
  3823.     bEnd:boolean;
  3824. begin
  3825.     Result := '';
  3826.     bEnd:=false;
  3827.     iEnd:=length(sAltText);
  3828.     repeat
  3829.     begin
  3830.         sChar := Copy(sAltText, iPos,1);
  3831.         Result := Result + sChar;
  3832.         if (sChar = ';') or (sChar = ' ') then
  3833.             bEnd:=true
  3834.         else
  3835.             Inc(iPos);
  3836.     end;
  3837.     until (iPos > iEnd) or bEnd;
  3838.  
  3839. end;
  3840.  
  3841. var
  3842.     sChar, sNewTag: String;
  3843.     sOldTag, sAltTag, sNewAltTag: String;
  3844.     iCount, iStart, iAltCount: Integer;
  3845.     tElement: Variant;
  3846.     iChanges, iPos: Integer;
  3847. begin
  3848.      {-= MrKistic - 20 November 197 =-}
  3849.     iChanges := 0;
  3850.     iCount := 0;
  3851.     while iCount < Document.Length -1 do
  3852.     begin
  3853.         try
  3854.             sChar := Document.GetTextRange(iCount, iCount + 1);
  3855.             sChar := Trim(sChar);
  3856.             if Length(sChar) > 0 then
  3857.             begin
  3858.                 tElement := Document.GetElementAt(iCount, iStart);
  3859.                 if tElement.Type <> HTMLSYNTAXELEMENT_TEXT then
  3860.                 begin
  3861.                     if tElement.Type = HTMLSYNTAXELEMENT_TAG then
  3862.                     begin
  3863.                         sNewTag := Document.GetTextRange(iStart, iStart + tElement.Length);
  3864.                         if GetTagName(sNewTag) = 'Image' then
  3865.                         begin
  3866.                             sOldTag := sNewTag;
  3867.                             iPos := Pos('alt', LowerCase(sNewTag));
  3868.                             if iPos > 0 then
  3869.                             begin
  3870.                                 sAltTag := GetAttribute(sNewTag, 'alt');
  3871.                                 sNewAltTag := '';
  3872.  
  3873.                                 //Loop thru alt tag and convert it, then replace it in the document
  3874.                                 if Length(sAltTag) > 0 then
  3875.                                 begin
  3876.                                     (*mg261197  for iAltCount := 1 to Length(sAltTag) do *)
  3877.                                     iAltCount:=1;
  3878.                                     while iAltCount<Length(sAltTag)+1 do
  3879.                                     begin
  3880.                             (*mg261197  if not(FindExistingTag(Copy(sAltTag, iAltCount, Length(sAltTag)))) then *)
  3881.                                         sNewTag:=GetAltWord(sAltTag,iAltCount);
  3882.                                         if not(FindExistingTag(sNewTag)) then
  3883.                                         begin
  3884.                                             sChar := sAltTag[iAltCount];
  3885.                                             if (Ord(sChar[1]) > 122) or (sChar = '>') or
  3886.                                                (sChar = '<') or (sChar='&') or
  3887.                                                (sChar = '"') then
  3888.                                             begin
  3889.                                                 //find in list and replace with tag
  3890.                                                 sNewTag := FindTagInList(sChar);
  3891.                                                 if sNewTag <> '' then
  3892.                                                 begin
  3893.                                                     sNewAltTag := sNewAltTag + sNewTag;
  3894.                                                     Inc(iChanges);
  3895.                                                 end;
  3896.                                             end
  3897.                                             else
  3898.                                                 sNewAltTag := sNewAltTag + sChar;
  3899.                                             inc(iAltCount);
  3900.                                         end
  3901.                                         else
  3902.                                         begin
  3903.                                             sNewAltTag := sNewAltTag + sNewTag;
  3904.                                             iAltCount:=iAltCount+length(sNewTag);
  3905.                                         end;
  3906.                                     end;
  3907.                                     sNewTag := sOldTag;
  3908.                                     ReplaceAttribute(sNewTag, 'alt', sNewAltTag);
  3909.                                     Document.ReplaceText(iCount, Length(sOldTag), sNewTag);
  3910.                                 end;
  3911.                                 iCount := iCount + Length(sNewTag)-1;
  3912.                             end
  3913.                             else
  3914.                                 iCount := iCount + tElement.Length - 1;
  3915.                         end
  3916.                         else
  3917.                             iCount := iCount + tElement.Length - 1;
  3918.                     end
  3919.                     else
  3920.                         iCount := iCount + tElement.Length - 1;
  3921.                 end
  3922.                 else if (Ord(sChar[1]) > 122) or (sChar = '>') or
  3923.                    (sChar = '<') or (sChar='&') or
  3924.                    (sChar = '"') then
  3925.                 begin
  3926.                     //Check that it isn't part of an already expanded char
  3927.                     sNewTag := GetWord(iCount, iStart + tElement.Length);
  3928.                     if not(FindExistingTag(sNewTag)) then
  3929.                     begin
  3930.                         //find in list and replace with tag
  3931.                         sNewTag := FindTagInList(sChar);
  3932.                         if sNewTag <> '' then
  3933.                         begin
  3934.                             Document.ReplaceText(iCount, Length(sChar), sNewTag);
  3935.                             iCount := iCount + Length(sNewTag) -1;
  3936.                             Inc(iChanges);
  3937.                         end;
  3938.                     end;
  3939.                 end;
  3940.             end;
  3941.             Inc(iCount);
  3942.         except
  3943.             //nada
  3944.         end;
  3945.     end;
  3946.     Result := iChanges;
  3947. end;
  3948.  
  3949. procedure TfrmDoc.DocConvertCase(bUpperCase : Boolean);
  3950. begin
  3951.     if bUpperCase then
  3952.         SelText := UpperCase(SelText)
  3953.     else
  3954.         SelText := LowerCase(SelText);
  3955. end;
  3956. function TfrmDoc.DocConvertTagCase(bPublishing, bUpperCase : Boolean) : Integer;
  3957. begin
  3958.      //bUpperCase is only read if we are not publishing, because then the preference is read instead.
  3959.      result := 0;
  3960.      if bPublishing then
  3961.      begin
  3962.         if tOptions.PublishTagCase = 1 then
  3963.            result := Document.MakeAllNameUpper
  3964.         else if tOptions.PublishTagCase = 2 then
  3965.            result := Document.MakeAllNameLower;
  3966.      end
  3967.      else
  3968.      begin
  3969.           if bUppercase then
  3970.              Document.MakeAllNameUpper
  3971.           else
  3972.              Document.MakeAllNameLower;
  3973.           MainForm.DirtyBird(True);
  3974.           HideToolbarShit(True);
  3975.      end;
  3976. end;
  3977.  
  3978. function TfrmDoc.DocPublishAndSave : Integer;
  3979.  
  3980. { Local Procedure }
  3981. function ReplaceAll(sFind, sReplace: String): Integer;
  3982. var
  3983.     iLastPos: Integer;
  3984.     iPos: Integer;
  3985. begin
  3986.     Result := 0;
  3987.     iLastPos := 0;
  3988.     iPos := 0;
  3989.     while (iLastPos < (Document.Length - 1)) and (iPos <> -1) do
  3990.     begin
  3991.         iPos := Find(sFind, iLastPos, True, False);
  3992.         if iPos > -1 then
  3993.         begin
  3994.             //string found
  3995.             //check for text only
  3996.             {tElement := Document.GetElementAt(iPos, iStart);
  3997.             if tElement.Type = HTMLSYNTAXELEMENT_TEXT then}
  3998.             begin
  3999.                 Document.ReplaceText(iPos, Length(sFind), sReplace);
  4000.                 iLastPos := iPos + Length(sReplace);
  4001.                 Inc(Result);
  4002.             end;
  4003.         end;
  4004.     end;
  4005. end;
  4006.  
  4007. { DocPublishAndSave }
  4008. var
  4009.     iCount, iChanges: Integer;
  4010.     //iLastPos : Integer; {Hint}
  4011.     sFind, sReplace: String;
  4012.     slReplace: TStringList;
  4013.     lDetails: TList;
  4014.     Details: ^TReplaceDetails;
  4015. begin
  4016.     {-= MrKistic - 19 November 1997 =-}
  4017.     {-= new =-}
  4018.     {if tOptions.PublishToDir and (DirectoryExists(tProject.PublishDirectory)) then
  4019.     begin
  4020.         iChanges := PublishDocumentInAShouseyManner
  4021.     end
  4022.     else}
  4023.     begin
  4024.         iChanges := 0;
  4025.         begin
  4026.             lDetails := TList.Create;
  4027.             try
  4028.                 tProject.ReadPubReplaceDetails(lDetails);
  4029.                 for iCount := 0 to lDetails.Count - 1 do
  4030.                 begin
  4031.                     Details := lDetails[iCount];
  4032.                     sFind := Details.sFrom;
  4033.                     if Details.bUseFile then
  4034.                     begin
  4035.                       if FileExists(Details.sFileName) then
  4036.                       begin
  4037.                         slReplace := TStringList.Create;
  4038.                         try
  4039.                           slReplace.LoadFromFile(Details.sFileName);
  4040.                           iChanges := iChanges + ReplaceAll(sFind, slReplace.Text);
  4041.                         finally
  4042.                           slReplace.Free;
  4043.                         end;
  4044.                       end;
  4045.                     end
  4046.                     else if Length(Details.sFrom) > 0 then
  4047.                     begin
  4048.                       sReplace := Details.sTo;
  4049.                       iChanges := iChanges + ReplaceAll(sFind, sReplace);
  4050.                     end;
  4051.                 end;
  4052.                 if tProject.PublishCR then
  4053.                 begin
  4054.                     iChanges := iChanges + DocConvertCR(False);
  4055.                 end;
  4056.                 SetFileFormat(DocEOLType(tOptions.PublishFileFormat));
  4057.                 if tProject.PublishSlash then
  4058.                 begin
  4059.                     iChanges := iChanges + DocConvertSlash;
  4060.                 end;
  4061.                 if tOptions.PublishExtChar then
  4062.                 begin
  4063.                     iChanges := iChanges + DocConvertExtChar;
  4064.                 end;
  4065.                 iChanges := iChanges + PublishFields;
  4066.             finally
  4067.                 lDetails.Free;
  4068.             end;
  4069.         end;
  4070.         Save;
  4071.     end;
  4072.     Result := iChanges;
  4073. end;
  4074.  
  4075. { Page Sniffer }
  4076.  
  4077. function TfrmDoc.SniffElements(sResult: TStringList; bIncludePositions: Boolean): Integer;
  4078. {*****************************************************************************
  4079. *  Module:         fDoc
  4080. *  Version:        1.1
  4081. *  Procedure:      SniffElements
  4082. *  Description:    Searches Document for tags and populates sResult with em'
  4083. *****************************************************************************}
  4084. var
  4085.     tElement: Variant;
  4086.     iPos, iStart, iEnd: Integer;
  4087. begin
  4088.     sResult.Clear;
  4089.     while iPos < (Document.Length -1) do
  4090.     begin
  4091.         tElement := Document.GetElementAt(iPos, iStart);
  4092.         iEnd := iStart + tElement.Length;
  4093.         if iEnd = Document.Length then
  4094.             iEnd := iEnd - 1;
  4095.         if tElement.Type = HTMLSYNTAXELEMENT_TAG then
  4096.         begin
  4097.             if bIncludePositions then
  4098.                sResult.Add(IntToStr(iStart)+ ',' + Document.GetTextRange(iStart, iEnd))
  4099.             else
  4100.                sResult.Add(Document.GetTextRange(iStart, iEnd));
  4101.         end;
  4102.         iPos := iEnd;
  4103.     end;    //while
  4104.     Result := sResult.Count;
  4105. end;
  4106.  
  4107. procedure TfrmDoc.UpdateTagColors;
  4108. var
  4109.     sColorValues: TStringList;
  4110.     i: Integer;
  4111. begin
  4112.     //LockWindowUpdate(rtfDoc.Handle);
  4113.     sColorValues:=Tstringlist.create;
  4114.     try
  4115.     begin
  4116.     if tReg.OpenTo(INI_HTML_TAGS, False) then
  4117.         begin
  4118.             if tReg.OpenKey(INI_TAGS_COLOR, False) then
  4119.             begin
  4120.                 tReg.GetSectionValues(sColorValues);
  4121.                 //rtfDoc.RemoveAllExceptionTags;
  4122.                 for i := 0 to sColorValues.Count - 1 do
  4123.                 begin
  4124.                     if sColorValues.Names[i] <> 'Default' then
  4125.                         rtfDoc.AddExceptionTag(sColorValues.Names[i],HTMLToColor(GetNewForeColor(sColorValues.Values[sColorValues.Names[i]])), HTMLToColor(GetNewBackColor(sColorValues.Values[sColorValues.Names[i]])))
  4126.                     else
  4127.                     begin
  4128.                          if spdTag.Down then
  4129.                          begin
  4130.                              if tOptions.ColorTagBack <> '' then
  4131.                                 rtfDoc.FormatBackcolor[4] := HTMLToColor(tOptions.ColorTagBack)
  4132.                              else
  4133.                                 rtfDoc.FormatBackcolor[4] := HTMLToColor(GetNewBackColor(sColorValues.Values['Default']));
  4134.                              if tOptions.ColorTagText <> '' then
  4135.                                 rtfDoc.FormatTextcolor[4] := HTMLToColor(tOptions.ColorTagText)
  4136.                              else
  4137.                                 rtfDoc.FormatTextcolor[4] := aColors[GetForeColor(sColorValues.Values['Default'])];
  4138.                          end;
  4139.                     end;
  4140.                 end;
  4141.             end;
  4142.         end;
  4143.  
  4144.         if spdTag.Down then
  4145.         begin
  4146.             rtfDoc.Repaint;
  4147.             //rtfDoc.HighlightStyle := HTMLEDITVIEW_NOTAGSYNTAX;
  4148.             //rtfDoc.HighlightStyle := HTMLEDITVIEW_TAGS; //kin 190997
  4149.         end
  4150.         else
  4151.         begin
  4152.             if (tOptions.ColorTagBack <> '') then
  4153.                rtfDoc.FormatBackcolor[4] := HTMLToColor(tOptions.ColorTagBack)
  4154.             else
  4155.                rtfDoc.FormatBackcolor[4] := clWhite;
  4156.             if (tOptions.ColorTagText <> '') then
  4157.                rtfDoc.FormatTextcolor[4] := HTMLToColor(tOptions.ColorTagText)
  4158.             else
  4159.                rtfDoc.FormatTextcolor[4] := clBlue;  //Sav 230997
  4160.         end;
  4161.     end
  4162.     finally
  4163.         sColorValues.free;
  4164.         //LockWindowUpdate(0);
  4165.     end;
  4166.  
  4167. end;
  4168.  
  4169. procedure TfrmDoc.UpdateSyntax;
  4170. begin
  4171.     Status('Reloading Syntax Files...');
  4172.     Document.Reparse;
  4173. end;
  4174.  
  4175. procedure TfrmDoc.rtfDocMouseUp(Sender: TObject; Button: TMouseButton;
  4176.   Shift: TShiftState; X, Y: Integer);
  4177. begin
  4178.     if Button = mbRight then
  4179.     begin
  4180.         Screen.Cursor := crHourGlass;
  4181.         try
  4182.            MainViewRightClick(X, Y);
  4183.         finally
  4184.            Screen.Cursor := crDefault;
  4185.         end;
  4186.     end;
  4187. end;
  4188.  
  4189. procedure TfrmDoc.rtfDocKeyDown(Sender: TObject; var Key: Word;
  4190.   Shift: TShiftState);
  4191. begin
  4192.   try
  4193.     if (ssShift in Shift) and (Key = 13) then
  4194.     begin
  4195.         DocBreak;
  4196.         Key := 0;
  4197.     end
  4198.     else if (ssCtrl in Shift) and (Key = 32) then
  4199.     begin
  4200.         InsertText(' ', SelStart);
  4201.         Key := 0;
  4202.     end
  4203.     else if (ssAlt in Shift) and (Key = 13) then
  4204.     begin
  4205.         DocPara;
  4206.         //InsertText('<P>', SelStart);
  4207.         Key := 0;
  4208.     end
  4209.     else
  4210.     //Test for preview functions
  4211.     if (Key = VK_F9) then
  4212.     begin
  4213.        try
  4214.           if (MainForm is TfrmMainRover) then
  4215.           begin
  4216.             if ssCtrl in Shift then
  4217.                (MainForm as TfrmMainRover).PosRefreshRover(PreviewFilename, Text)
  4218.             else
  4219.                DocPreviewWithLastBrowser;
  4220.           end
  4221.           else
  4222.             DocPreviewWithLastBrowser;
  4223.        except
  4224.        end;
  4225.     end
  4226.     else
  4227.     // Sav 01-09-97
  4228.     //When F1 is pressed, bring up the main help screen.
  4229.     if Key = VK_F1 then
  4230.     begin
  4231.          application.helpfile := filepath(ExtractFileDir(Application.ExeName), 'HotDog5.hlp');
  4232.          application.helpCommand(Help_Finder,0);
  4233.     end
  4234.     else
  4235.     //Find
  4236.     if Key = VK_F3 then
  4237.     begin
  4238.            DocFindF3;
  4239.     end
  4240.     else
  4241.     if  (ssCtrl in Shift) and (Key = 13) then
  4242.     begin
  4243.         if Assigned(MainForm.propSheet) then
  4244.             MainForm.PropSheet.SetFocus;
  4245.     end
  4246.     else
  4247.     if (Shift = [ssAlt]) and ((Key >= 48) and (Key <= 57)) then
  4248.     begin
  4249.         if Assigned(MainForm.strClipboard) then
  4250.             PasteFromClipboard(Key);
  4251.     end
  4252.     else
  4253.     if (Shift = [ssAlt,ssShift]) and ((Key >= 48) and (Key <= 57)) then
  4254.     begin
  4255.         if Assigned(MainForm.strClipboard) then
  4256.             CopyToClipboard(Key);
  4257.     end;
  4258.   except
  4259.   end;
  4260. end;
  4261.  
  4262. procedure TfrmDoc.rtfDocEditModeToggled(Sender: TObject;
  4263.   bOverwrite: Wordbool);
  4264. begin
  4265.     spdInsert.Down := bOverwrite;
  4266. end;
  4267.  
  4268. procedure TfrmDoc.rtfDocDocumentChanged(Sender: TObject; nAction: Smallint; nChangeAt, nChangeCount: Integer);
  4269. begin
  4270.     if (bFirstLoaded) and (text <> '') then
  4271.     begin
  4272.        if (Owner is TfrmMainRover) then
  4273.        begin
  4274.           (Owner as TfrmMainRover).PosRefreshRover(PreviewFilename, Text);
  4275.        end;
  4276.        bFirstLoaded := False;
  4277.     end;
  4278.     bRoverDirty := True;
  4279.     bDocDirty := True;
  4280. end;
  4281.  
  4282. procedure TfrmDoc.ClearCurrentElement;
  4283. begin
  4284.     tCurrentElement.iType := HTMLSYNTAXELEMENT_INVALID;
  4285.     tCurrentElement.sTagName := '';
  4286.     tCurrentElement.iStart := 0;
  4287.     tCurrentElement.iLength := 0;
  4288. end;
  4289.  
  4290. function TfrmDoc.CanUndo: Boolean;
  4291. begin
  4292.     if bSetup then
  4293.         //Result := Document.CanUndo
  4294.         Result := Document.UndoManager.CanUndo //kin 190997
  4295.     else
  4296.         Result := False;
  4297. end;
  4298.  
  4299. function TfrmDoc.GetUndoCount : Integer;
  4300. begin
  4301.      try
  4302.         result := Document.UndoManager.UndoCount;
  4303.      except
  4304.         result := 0;
  4305.      end;
  4306. end;
  4307.  
  4308. function TfrmDoc.GetUndoItemText(Index : Integer) : String;
  4309. begin
  4310.      try
  4311.         If (Index > -1) and (Index <= (GetUndoCount - 1)) then
  4312.            result := Document.UndoManager.UndoAction[Index].Description;
  4313.      except
  4314.         result := '';
  4315.      end;
  4316. end;
  4317.  
  4318. procedure TfrmDoc.UndoTo(Index : Integer);
  4319. begin
  4320.      try
  4321.         If (Index > -1) and (Index <= (GetUndoCount - 1)) then
  4322.            Document.UndoManager.UndoTo(Document.UndoManager.UndoAction[Index]);
  4323.      except
  4324.      end;
  4325. end;
  4326.  
  4327. function TfrmDoc.GetNextUndoText : String;
  4328. //just returns the description of the next undo
  4329. begin
  4330.      try
  4331.           if CanUndo then
  4332.           begin
  4333.                Result := Document.UndoManager.UndoAction[GetUndoCount-1].Description;
  4334.           end;
  4335.      except
  4336.           Result := '';
  4337.      end;
  4338. end;
  4339.  
  4340. function TfrmDoc.CanRedo: Boolean;
  4341. begin
  4342.     try
  4343.        if bSetup then
  4344.              //Result := Document.CanRedo
  4345.           Result := Document.UndoManager.CanRedo //kin 190997
  4346.        else
  4347.           Result := False;
  4348.     except
  4349.           Result := False;
  4350.     end;
  4351. end;
  4352.  
  4353. function TfrmDoc.GetRedoCount : Integer;
  4354. begin
  4355.      try
  4356.         result := Document.UndoManager.RedoCount;
  4357.      except
  4358.         result := 0;
  4359.      end;
  4360. end;
  4361.  
  4362. procedure TfrmDoc.RedoTo(Index : Integer);
  4363. begin
  4364.      try
  4365.         If (Index > -1) and (Index <= (GetRedoCount - 1)) then
  4366.            Document.UndoManager.RedoTo(Document.UndoManager.RedoAction[Index]);
  4367.      except
  4368.      end;
  4369. end;
  4370.  
  4371. function TfrmDoc.GetRedoItemText(Index : Integer) : String;
  4372. begin
  4373.      try
  4374.         If (Index > -1) and (Index <= (GetRedoCount - 1)) then
  4375.            result := Document.UndoManager.RedoAction[Index].Description;
  4376.      except
  4377.         result := '';
  4378.      end;
  4379. end;
  4380.  
  4381.  
  4382.  
  4383. function TfrmDoc.GetNextRedoText : String;
  4384. //just returns the description of the next redo
  4385. begin
  4386.      try
  4387.         if CanRedo then
  4388.         begin
  4389.              Result := Document.UndoManager.RedoAction[Document.UndoManager.RedoCount-1].Description;
  4390.         end;
  4391.      except
  4392.         Result := '';
  4393.      end;
  4394. end;
  4395.  
  4396.  
  4397. procedure TfrmDoc.popViewMainPopup(Sender: TObject);
  4398. var
  4399.     bEnabled : Boolean;
  4400. begin
  4401.     try
  4402.        popMainCut.Enabled := (rtfDoc.SelectionStart <> rtfDoc.SelectionEnd);
  4403.        popMainDelete.Enabled := popMainCut.Enabled;
  4404.        popMainCopy.Enabled := popMainCut.Enabled;
  4405.        //popMainUndo.Enabled := Document.CanUndo;
  4406.        //popMainRedo.Enabled := Document.CanRedo;
  4407.        popMainUndo.Enabled := Document.UndoManager.CanUndo;
  4408.        popMainRedo.Enabled := Document.UndoManager.CanRedo;  // Kin 190997
  4409.        popMainPaste.Enabled := Clipboard.HasFormat(CF_TEXT);
  4410.        popMainSmartPaste.Enabled := popMainPaste.Enabled; 
  4411.  
  4412.        //Convert Menu Options
  4413.        bEnabled := (SelLength > 0);
  4414.        mnuRelToAbs.Enabled := bEnabled;
  4415.        mnuAbsToRel.Enabled := bEnabled;
  4416.        mnuConvertLower.Enabled := bEnabled;
  4417.        mnuConvertUpper.Enabled := bEnabled;
  4418.        mnuTable.Enabled := bEnabled;
  4419.        mnuBList.Enabled := bEnabled;
  4420.     except
  4421.     end;
  4422.     try
  4423.        //Macros
  4424.        mnuMacros.Enabled := False;
  4425.        SetupMacroMenu;
  4426.     except
  4427.     end;
  4428. end;
  4429.  
  4430. procedure TfrmDoc.PreviewImageClick(Sender : TObject);
  4431. begin
  4432.      rtfDoc.SetSelection(tCurrentElement.iStart, tCurrentElement.iLength);
  4433.      PreviewImage('');
  4434. end;
  4435. procedure TfrmDoc.popMainUndoClick(Sender: TObject);
  4436. begin
  4437.     DocUndo;
  4438. end;
  4439.  
  4440. procedure TfrmDoc.popMainRedoClick(Sender: TObject);
  4441. begin
  4442.     DocRedo;
  4443. end;
  4444.  
  4445. procedure TfrmDoc.popMainCutClick(Sender: TObject);
  4446. begin
  4447.     DocCut;
  4448. end;
  4449.  
  4450. procedure TfrmDoc.popMainCopyClick(Sender: TObject);
  4451. begin
  4452.     DocCopy;
  4453. end;
  4454.  
  4455. procedure TfrmDoc.popMainPasteClick(Sender: TObject);
  4456. begin
  4457.     DocPaste;
  4458. end;
  4459.  
  4460. procedure TfrmDoc.popMainDeleteClick(Sender: TObject);
  4461. begin
  4462.     DocDelete;
  4463. end;
  4464.  
  4465. function TfrmDoc.GetDocLength: Integer;
  4466. begin
  4467.     Result := Document.Length;
  4468. end;
  4469.  
  4470. { Form Elements }
  4471. procedure TfrmDoc.FormCheckBox;
  4472. begin
  4473.     try
  4474.        Screen.Cursor := crHourglass;
  4475.        Application.CreateForm(TfrmCheckBox, frmCheckBox);
  4476.     finally
  4477.        Screen.Cursor := crDefault;
  4478.     end;
  4479.     if SelLength > 0 then
  4480.     begin
  4481.         frmCheckBox.sTag := SelText;
  4482.     end;
  4483.     frmCheckBox.ShowModal;
  4484.     if Length(frmCheckBox.sTag) > 0 then
  4485.         AddText(frmCheckBox.sTag, '', False);
  4486.     frmCheckBox.free;
  4487. end;
  4488.  
  4489.  
  4490. procedure TfrmDoc.FormTextBox;
  4491. begin
  4492.     try
  4493.        Screen.Cursor := crHourglass;
  4494.        Application.CreateForm(TfrmFText, frmFText);
  4495.     finally
  4496.        Screen.Cursor := crDefault;
  4497.     end;
  4498.     if SelLength > 0 then
  4499.     begin
  4500.         frmFText.sTag := SelText;
  4501.     end;
  4502.     frmFText.ShowModal;
  4503.     if Length(frmFText.sTag) > 0 then
  4504.         AddText(frmFText.sTag, '', False);
  4505.     frmFText.free;
  4506. end;
  4507.  
  4508. procedure TfrmDoc.FormHidden;
  4509. begin
  4510.     try
  4511.        Screen.Cursor := crHourglass;
  4512.        Application.CreateForm(TfrmHidden, frmHidden);
  4513.     finally
  4514.        Screen.Cursor := crDefault;
  4515.     end;
  4516.     if SelLength > 0 then
  4517.     begin
  4518.         frmHidden.sTag := SelText;
  4519.     end;
  4520.     frmHidden.ShowModal;
  4521.     if Length(frmHidden.sTag) > 0 then
  4522.         AddText(frmHidden.sTag, '', False);
  4523.     frmHidden.free;
  4524. end;
  4525.  
  4526. procedure TfrmDoc.FormPassword;
  4527. begin
  4528.     try
  4529.        Screen.Cursor := crHourglass;
  4530.        Application.CreateForm(TfrmPassword, frmPassword);
  4531.     finally
  4532.        Screen.Cursor := crDefault;
  4533.     end;
  4534.     if SelLength > 0 then
  4535.     begin
  4536.         frmPassword.sTag := SelText;
  4537.     end;
  4538.     frmPassword.ShowModal;
  4539.     if Length(frmPassword.sTag) > 0 then
  4540.         AddText(frmPassword.sTag, '', False);
  4541.     frmPassword.free;
  4542. end;
  4543.  
  4544. procedure TfrmDoc.FormRadio;
  4545. begin
  4546.     try
  4547.        Screen.Cursor := crHourglass;
  4548.        Application.CreateForm(TfrmRadio, frmRadio);
  4549.     finally
  4550.        Screen.Cursor := crDefault;
  4551.     end;
  4552.     if SelLength > 0 then
  4553.     begin
  4554.         frmRadio.sTag := SelText;
  4555.     end;
  4556.     frmRadio.ShowModal;
  4557.     if Length(frmRadio.sTag) > 0 then
  4558.         AddText(frmRadio.sTag, '', False);
  4559.     frmRadio.free;
  4560. end;
  4561.  
  4562. procedure TfrmDoc.FormReset;
  4563. begin
  4564.     try
  4565.        Screen.Cursor := crHourglass;
  4566.        Application.CreateForm(TfrmReset, frmReset);
  4567.     finally
  4568.        Screen.Cursor := crDefault;
  4569.     end;
  4570.     if SelLength > 0 then
  4571.     begin
  4572.         frmReset.sTag := SelText;
  4573.     end;
  4574.     frmReset.ShowModal;
  4575.     if Length(frmReset.sTag) > 0 then
  4576.         AddText(frmReset.sTag, '', False);
  4577.     frmReset.free;
  4578. end;
  4579.  
  4580. procedure TfrmDoc.FormSubmit;
  4581. begin
  4582.     try
  4583.        Screen.Cursor := crHourglass;
  4584.        Application.CreateForm(TfrmSubmit, frmSubmit);
  4585.     finally
  4586.        Screen.Cursor := crDefault;
  4587.     end;
  4588.     if SelLength > 0 then
  4589.     begin
  4590.         frmSubmit.sTag := SelText;
  4591.     end;
  4592.     frmSubmit.ShowModal;
  4593.     if Length(frmSubmit.sTag) > 0 then
  4594.         AddText(frmSubmit.sTag, '', False);
  4595.     frmSubmit.free;
  4596. end;
  4597.  
  4598. procedure TfrmDoc.FormTextArea;
  4599. begin
  4600.     try
  4601.        Screen.Cursor := crHourglass;
  4602.        Application.CreateForm(TfrmTextArea, frmTextArea);
  4603.     finally
  4604.        Screen.Cursor := crDefault;
  4605.     end;
  4606.     if SelLength > 0 then
  4607.     begin
  4608.         frmTextArea.sTag := SelText;
  4609.     end;
  4610.     frmTextArea.ShowModal;
  4611.     if Length(frmTextArea.sTag) > 0 then
  4612.         AddText(frmTextArea.sTag, '', False);
  4613.     frmTextArea.free;
  4614. end;
  4615.  
  4616. procedure TfrmDoc.FormList;
  4617. begin
  4618.     try
  4619.        Screen.Cursor := crHourglass;
  4620.        Application.CreateForm(TfrmList, frmList);
  4621.     finally
  4622.        Screen.Cursor := crDefault;
  4623.     end;
  4624.     if SelLength > 0 then
  4625.     begin
  4626.         frmList.sTag := SelText;
  4627.     end;
  4628.     if frmList.ShowModal = mrOk Then
  4629.     begin
  4630.         if Length(frmList.sTag) > 0 then
  4631.             AddText(frmList.sTag, '', False);
  4632.     end;
  4633.     frmList.free;
  4634. end;
  4635.  
  4636. procedure TfrmDoc.FormImage;
  4637. begin
  4638.     try
  4639.        Screen.Cursor := crHourglass;
  4640.        Application.CreateForm(TfrmFImage, frmFImage);
  4641.     finally
  4642.        Screen.Cursor := crDefault;
  4643.     end;
  4644.     if SelLength > 0 then
  4645.     begin
  4646.         frmFImage.sTag := SelText;
  4647.     end;
  4648.     if frmFImage.ShowModal = mrOk Then
  4649.     begin
  4650.         if Length(frmFImage.sTag) > 0 then
  4651.             AddText(frmFImage.sTag, '', False);
  4652.     end;
  4653.     frmFImage.free;
  4654. end;
  4655.  
  4656. procedure TfrmDoc.FormWizard;
  4657. begin
  4658.     try
  4659.        Screen.Cursor := crHourglass;
  4660.        Application.CreateForm(TfrmFormWiz, frmFormWiz);
  4661.     finally
  4662.       Screen.Cursor := crDefault;
  4663.     end; 
  4664.     if frmFormWiz.Showmodal = mrOk then
  4665.     begin
  4666.         if Length(frmFormWiz.sTag) > 0 then
  4667.            AddText(frmFormWiz.sTag, '', False);
  4668.     end;
  4669.     frmFormWiz.Free;
  4670. end;
  4671.  
  4672. procedure TfrmDoc.FormShow(Sender: TObject);
  4673. begin
  4674.     UpdateTagColors;
  4675.     if not(bSetup) then
  4676.        Close
  4677.     else
  4678.         HotDogSound(INI_SOUNDS_OPEN);
  4679. end;
  4680.  
  4681. { Spelling }
  4682. procedure TfrmDoc.CheckSpelling;
  4683. var
  4684.     bOneWord : Boolean;
  4685. begin
  4686.      bOneWord := False;
  4687.      try
  4688.         if SelLength > 0 then
  4689.             bOneWord := True;
  4690.         Screen.Cursor := crHourglass;
  4691.         //Create the spelling stuff fist time run
  4692.         if slSpellAddlist = nil then
  4693.         begin
  4694.            sID := SSCE_OpenSession;
  4695.            sID := SSCE_GetSID;
  4696.            slSpellAddList := TStringList.Create;
  4697.         end;
  4698.         Application.CreateForm(TfrmSpell, frmSpell);
  4699.      finally
  4700.         Screen.Cursor := crDefault;
  4701.      end;
  4702.     frmSpell.ShowModal;
  4703.     frmSpell.Free;
  4704.     if frmSpell.ModalResult = mrOK then
  4705.     begin
  4706.         if  bOneWord then
  4707.             MessageDlg('HotDog has finished checking the spelling of the selected block.', mtInformation, [mbOK], 0)
  4708.         else
  4709.             MessageDlg('HotDog has finished checking the spelling in this document.', mtInformation, [mbOK], 0);
  4710.     end;
  4711.     SetSelection(SelStart, 0);
  4712. end;
  4713.  
  4714. function TfrmDoc.GetNextSpellWord;
  4715. var
  4716.     iStart{, iEnd}: Integer; {Hint}
  4717.     tElement: Variant;
  4718.     sWord: String;
  4719.     setWhite: Characters;
  4720.     sChar: String;
  4721. begin
  4722.     setWhite := [#32, #13, #10, #9];
  4723.     (*',', '.', '?', '(', '{', '[', ']', '}', ')', '+', '=', '~', '!', '#', '$', '%', '^', '&', '*', '@', ':',
  4724.     ';', '`', '\', '/', '"', '*', '<', '>'];*)
  4725.     Result := '';
  4726.     repeat
  4727.         if iSpellPos < iSpellEnd then
  4728.         begin
  4729.             tElement := Document.GetElementAt(iSpellPos, iStart);
  4730.             if (tElement.Type = HTMLSYNTAXELEMENT_TEXT)    then
  4731.             begin
  4732.                 //sWord := GetWordAtPos(iSpellPos, iStart, iEnd)
  4733.                 sChar := Document.GetTextRange(iSpellPos, iSpellPos + 1);
  4734.                 while not(sChar[1] in setWhite) do
  4735.                 begin
  4736.                     sWord := sWord + Document.GetTextRange(iSpellPos, iSpellPos + 1);
  4737.                     Inc(iSpellPos);
  4738.                 end;
  4739.             end
  4740.             else
  4741.                 iSpellPos := iStart + tElement.Length;
  4742.         end;
  4743.     until (iSpellPos >= iSpellEnd) or (tElement.Type = HTMLSYNTAXELEMENT_TEXT);
  4744.     if iSpellPos >= iSpellEnd then
  4745.         Result := '__SPELL_NO_MORE_'
  4746.     else
  4747.         Result := sWord;
  4748.     //iSpellPos := iEnd; {Hint}
  4749. end;
  4750.  
  4751. procedure TfrmDoc.SelectSpellWord;
  4752. begin
  4753.     rtfDoc.SelectWordAtPos(iSpellPos - 1);
  4754. end;
  4755.  
  4756. procedure TfrmDoc.CorrectSpellWord(sWord: String);
  4757. begin
  4758.     SelText := sWord;
  4759. end;
  4760.  
  4761. procedure TfrmDoc.DocAbsToRel;
  4762. var
  4763.    //lBackTo: Integer; {Hint}
  4764.     bDone: Boolean;
  4765.     lStart: Integer;
  4766.     sToChange: String;
  4767.     bOnce: Boolean;
  4768.     iTagStart, iTagEnd: Integer;
  4769.     sNewTag: String;
  4770. begin
  4771.     if not(FileExists(sDocFileName)) then
  4772.     begin
  4773.         if MessageDlg('This document must be saved before relative links can be created. Do you want to save the document now?', mtInformation, [mbYes, mbNo], 0) = mrYes then
  4774.             Save;
  4775.     end;
  4776.  
  4777.     if FileExists(sDocFileName) then
  4778.     begin
  4779.         If Length(SelText) = 0 Then
  4780.         begin
  4781.             //lBackTo := SelStart; {Hint}
  4782.             rtfDoc.SetSelection(0, 0);
  4783.         end;
  4784.         {else
  4785.             bOnce := True;} {Hint}
  4786.  
  4787.         lStart := SelStart;
  4788.         bDone := False;
  4789.         bOnce := False; // Sav 13-09-97
  4790.         while not(bDone) do
  4791.         begin
  4792.             //If something wasn't already highlighted
  4793.             //then go find it
  4794.             If not(bOnce) then
  4795.             begin
  4796.                 //Find(sString: String; iStart: Integer; bCase: Boolean; bWholeWord: Boolean): LongInt;
  4797.                 iTagStart := Find('file:///', lStart, False, False);
  4798.  
  4799.                 //Cheat a bit
  4800.                 {ltemp = Len(MainForm.ActiveForm.txtDoc.selText)
  4801.                 If ltemp > 0 Then
  4802.                     MainForm.ActiveForm.txtDoc.selStart = MainForm.ActiveForm.txtDoc.selStart + 1
  4803.                     MainForm.ActiveForm.txtDoc.selLength = ltemp
  4804.                     MainForm.ActiveForm.txtDoc.Span DQ, True, True
  4805.                 End If}
  4806.                 if iTagStart > -1 then
  4807.                    iTagEnd := Find('"', iTagStart, False, False);
  4808.             end;
  4809.             if (iTagStart > -1) and (iTagEnd > -1) then
  4810.             begin
  4811.                 //lStart := iTagStart;
  4812.                 sToChange := Document.GetTextRange(iTagStart, iTagEnd);
  4813.                 sNewTag := AbsoluteToRelative(sDocFileName, UrlToFile(sToChange));
  4814.                 Document.ReplaceText(iTagStart, Length(sToChange), sNewTag);
  4815.                 lStart := iTagStart + Length(sNewTag);
  4816.                 if bOnce then
  4817.                     bDone := True;
  4818.             end
  4819.             else
  4820.                 bDone := True;
  4821.             end;
  4822.     end;
  4823. end;
  4824.  
  4825. procedure TfrmDoc.DocRelToAbs;
  4826. var
  4827.     sCurrRef: String;     //The current reference
  4828.     sOutRef : String;     //New ref
  4829.     sDocDir: String;     //The directory the doc lives in
  4830.     sResult: String;
  4831. begin
  4832.     if not(FileExists(sDocFileName)) then
  4833.     begin
  4834.         if MessageDlg('This document must be saved before relative links can be created. Do you want to save the document now?', mtInformation, [mbYes, mbNo], 0) = mrYes then
  4835.             Save;
  4836.     end;
  4837.  
  4838.     if FileExists(sDocFileName) then
  4839.     begin
  4840.         if SelText = '' Then
  4841.             MessageDlg('Please highlight the reference you wish to change.', mtError, [mbOK], 0)
  4842.         else
  4843.         begin
  4844.             sDocDir := ExtractFileDir(sDocFileName);
  4845.             sCurrRef := SelText;
  4846.  
  4847.             if Copy(sCurrRef, 1, 8) = 'file:///' then
  4848.                 sCurrRef := URLToFile(sCurrRef);
  4849.  
  4850.             if (Pos('|', sCurrRef) > 0) or (Pos(':', sCurrRef) > 0) then
  4851.                 MessageDlg('This does not appear to be a relative reference.', mtError,
  4852.                             [mbOK], 0)
  4853.             else
  4854.             begin
  4855.                 sOutRef := RelativeToAbsolute(FilePath(sDocDir, 'kaiser.html'), sCurrRef);
  4856.                 //No checking of this result yet...
  4857.                 if sCurrRef[1] = '"' then
  4858.                     sResult := '"' + (FileToURL(sOutRef)) + '"'
  4859.                 else
  4860.                     sResult := FileToURL(sOutRef);
  4861.             end;
  4862.  
  4863.             if Length(sResult) > 0 Then
  4864.                 SelText := sResult
  4865.             else
  4866.                 MessageDlg('HotDog couldn''t convert this reference.', mtError, [mbOK], 0);
  4867.         end;
  4868.     end;
  4869. end;
  4870.  
  4871. procedure TfrmDoc.timAutoSaveTimer(Sender: TObject);
  4872. begin
  4873.     AutoSave;
  4874. end;
  4875.  
  4876. procedure TfrmDoc.AutoSave;
  4877. begin
  4878.     if FileExists(sDocFileName) then
  4879.     begin
  4880.         Status('AutoSaving Document...');
  4881.         Save;
  4882.         Status('None');
  4883.     end;
  4884. end;
  4885.  
  4886. procedure TfrmDoc.DocProperties;
  4887. begin
  4888.     Screen.Cursor := crHourglass;
  4889.     Application.CreateForm(TfrmDocProperties, frmDocProperties);
  4890.     try
  4891.        frmDocProperties.sDocFileName := sDocFileName;
  4892.        frmDocProperties.sBodyTag := GetTag(Document.Text, '<BODY', '>');
  4893.        frmDocProperties.sHeadTag := GetTagGuts(Document.Text, '<HEAD>', '</HEAD>');
  4894.        frmDocProperties.ShowModal;
  4895.     finally
  4896.        Screen.Cursor := crDefault;
  4897.        frmDocProperties.Free;
  4898.     end;
  4899. end;
  4900.  
  4901. procedure TfrmDoc.DocMeta;
  4902. begin
  4903.     Screen.Cursor := crHourglass;
  4904.     Application.CreateForm(TfrmMeta, frmMeta);
  4905.     try
  4906.         frmMeta.sDocFileName := sDocFileName;
  4907.         frmMeta.sBodyTag := GetTag(Document.Text, '<BODY', '>');
  4908.         frmMeta.sHeadTag := GetTagGuts(Document.Text, '<HEAD>', '</HEAD>');
  4909.         frmMeta.ShowModal;
  4910.     finally
  4911.        frmMeta.Free;
  4912.        Screen.Cursor := crDefault;
  4913.     end;
  4914. end;
  4915.  
  4916.  
  4917. procedure TfrmDoc.DocColor;
  4918. begin
  4919.      try
  4920.        // Showmessage(seltext);
  4921.      finally
  4922.      end;
  4923. end;    //Can't do this yet - kin
  4924.  
  4925. procedure TfrmDoc.SetFileFormat(DocType: DocEOLType);
  4926. begin
  4927.     Document.EOLType := DocType;
  4928.     if DocType = EOLType_CRLF then
  4929.         spdFormat.glyph.LoadFromResourceName(hInstance, 'bmpWIN')
  4930.         //spdFormat.Caption := 'WIN'
  4931.     else if DocType = EOLType_LF then
  4932.         spdFormat.glyph.LoadFromResourceName(hInstance, 'bmpUNIX')
  4933.         //spdFormat.Caption := 'UNIX'
  4934.     else if DocType = EOLTYPE_CR then
  4935.         spdFormat.glyph.LoadFromResourceName(hInstance, 'bmpMAC');
  4936.         //spdFormat.Caption := 'MAC';
  4937. end;
  4938.  
  4939. procedure TfrmDoc.ToggleFileFormat;
  4940. var
  4941.    DocType: DocEOLType;
  4942. begin
  4943.     DocType := DocEOLType(Document.EOLType);
  4944.     if DocType = EOLType_CR then
  4945.       DocType := EOLType_CRLF
  4946.     else
  4947.       DocType := DocEOLType(Ord(DocType) + 1);
  4948.     SetFileFormat(DocType);
  4949. end;
  4950.  
  4951. procedure TfrmDoc.DocInsertTarget;
  4952. begin
  4953.     try
  4954.        Screen.Cursor := crHourglass;
  4955.        Application.CreateForm(TfrmInternalLink, frmInternalLink);
  4956.     finally
  4957.        Screen.Cursor := crDefault;     
  4958.     end;
  4959.     if SelLength > 0 then
  4960.     begin
  4961.         frmInternalLink.sTag := SelText;
  4962.     end;
  4963.     frmInternalLink.ShowModal;
  4964.     if Length(frmInternalLink.sTag) > 0 then
  4965.         AddText(frmInternalLink.sTag, '', False);
  4966.     frmInternalLink.free;
  4967. end;
  4968.  
  4969. procedure TfrmDoc.PartnerButton;
  4970. var
  4971.     tmpINI: TIniFile;
  4972.     sText: String;
  4973. begin
  4974.     tmpINI := TIniFile.Create(Filepath(tOptions.AutoDownloaderDir , 'Partner.ini'));
  4975.     try
  4976.         //'<A HREF="http://www.hotfiles.com"><IMG SRC="http://www.sausage.com/zdbutton.gif"></A>',
  4977.         sText := '<A HREF="';
  4978.         sText := sText + tmpIni.ReadString('Details', 'URL', '');
  4979.         sText := sText + '"><IMG SRC="';
  4980.         sText := sText + tmpIni.ReadString('Details', 'Image URL', '');
  4981.         sText := sText + '" BORDER=0>';
  4982.         AddText(sText, '</A>', True);
  4983.     finally
  4984.         tmpIni.Free;
  4985.     end;
  4986. end;
  4987.  
  4988. procedure TfrmDoc.LoadSyntaxColours(Document : THTMLEditView);
  4989. begin
  4990.      if tOptions.ColorTextBack <> '' then
  4991.           Document.FormatBackcolor[1] := HTMLToColor(tOptions.ColorTextBack);
  4992.      if tOptions.ColorTextText <> '' then
  4993.           Document.FormatTextcolor[1] := HTMLToColor(tOptions.ColorTextText);
  4994.      if tOptions.ColorTextStyle > -1 then
  4995.           Document.FormatStyle[1] := tOptions.ColorTextStyle;
  4996.      if tOptions.ColorOperatorBack <> '' then
  4997.           Document.FormatBackcolor[2] := HTMLToColor(tOptions.ColorOperatorBack);
  4998.      if tOptions.ColorOperatorText <> '' then
  4999.           Document.FormatTextcolor[2] := HTMLToColor(tOptions.ColorOperatorText);
  5000.      if tOptions.ColorOperatorStyle > -1 then
  5001.           Document.FormatStyle[2] := tOptions.ColorOperatorStyle;
  5002.      if tOptions.ColorErrorBack <> '' then
  5003.           Document.FormatBackcolor[3] := HTMLToColor(tOptions.ColorErrorBack);
  5004.      if tOptions.ColorErrorText <> '' then
  5005.           Document.FormatTextcolor[3] := HTMLToColor(tOptions.ColorErrorText);
  5006.      if tOptions.ColorErrorStyle > -1 then
  5007.           Document.FormatStyle[3] := tOptions.ColorErrorStyle;
  5008.      if tOptions.ColorTagBack <> '' then
  5009.           Document.FormatBackcolor[4] := HTMLToColor(tOptions.ColorTagBack);
  5010.      if tOptions.ColorTagText <> '' then
  5011.           Document.FormatTextcolor[4] := HTMLToColor(tOptions.ColorTagText);
  5012.      if tOptions.ColorTagStyle > -1 then
  5013.           Document.FormatStyle[4] := tOptions.ColorTagStyle;
  5014.      if tOptions.ColorAttributeBack <> '' then
  5015.           Document.FormatBackcolor[5] := HTMLToColor(tOptions.ColorAttributeBack);
  5016.      if tOptions.ColorAttributeText <> '' then
  5017.           Document.FormatTextcolor[5] := HTMLToColor(tOptions.ColorAttributeText);
  5018.      if tOptions.ColorAttributeStyle > -1 then
  5019.           Document.FormatStyle[5] := tOptions.ColorAttributeStyle;
  5020.      if tOptions.ColorCommentBack <> '' then
  5021.           Document.FormatBackcolor[6] := HTMLToColor(tOptions.ColorCommentBack);
  5022.      if tOptions.ColorCommentText <> '' then
  5023.           Document.FormatTextcolor[6] := HTMLToColor(tOptions.ColorCommentText);
  5024.      if tOptions.ColorCommentStyle > -1 then
  5025.           Document.FormatStyle[6] := tOptions.ColorCommentStyle;
  5026.      if tOptions.ColorStringBack <> '' then
  5027.           Document.FormatBackcolor[7] := HTMLToColor(tOptions.ColorStringBack);
  5028.      if tOptions.ColorStringText <> '' then
  5029.           Document.FormatTextcolor[7] := HTMLToColor(tOptions.ColorStringText);
  5030.      if tOptions.ColorStringStyle > -1 then
  5031.           Document.FormatStyle[7] := tOptions.ColorStringStyle;
  5032.      if tOptions.ColorIntegerBack <> '' then
  5033.           Document.FormatBackcolor[8] := HTMLToColor(tOptions.ColorIntegerBack);
  5034.      if tOptions.ColorIntegerText <> '' then
  5035.           Document.FormatTextcolor[8] := HTMLToColor(tOptions.ColorIntegerText);
  5036.      if tOptions.ColorIntegerStyle > -1 then
  5037.           Document.FormatStyle[8] := tOptions.ColorIntegerStyle;
  5038.      if tOptions.ColorEnumBack <> '' then
  5039.           Document.FormatBackcolor[9] := HTMLToColor(tOptions.ColorEnumBack);
  5040.      if tOptions.ColorEnumText <> '' then
  5041.           Document.FormatTextcolor[9] := HTMLToColor(tOptions.ColorEnumText);
  5042.      if tOptions.ColorEnumStyle > -1 then
  5043.           Document.FormatStyle[9] := tOptions.ColorEnumStyle;
  5044.      if tOptions.ColorColorBack <> '' then
  5045.           Document.FormatBackcolor[10] := HTMLToColor(tOptions.ColorColorBack);
  5046.      if tOptions.ColorColorText <> '' then
  5047.           Document.FormatTextcolor[10] := HTMLToColor(tOptions.ColorColorText);
  5048.      if tOptions.ColorColorStyle > -1 then
  5049.           Document.FormatStyle[10] := tOptions.ColorColorStyle;
  5050.      if tOptions.ColorURLBack <> '' then
  5051.           Document.FormatBackcolor[11] := HTMLToColor(tOptions.ColorURLBack);
  5052.      if tOptions.ColorURLText <> '' then
  5053.           Document.FormatTextcolor[11] := HTMLToColor(tOptions.ColorURLText);
  5054.      if tOptions.ColorURLStyle > -1 then
  5055.           Document.FormatStyle[11] := tOptions.ColorURLStyle;
  5056.      if tOptions.ColorInvisibleBack <> '' then
  5057.           Document.FormatBackcolor[12] := HTMLToColor(tOptions.ColorInvisibleBack);
  5058.      if tOptions.ColorInvisibleText <> '' then
  5059.           Document.FormatTextcolor[12] := HTMLToColor(tOptions.ColorInvisibleText);
  5060.      if tOptions.ColorInvisibleStyle > -1 then
  5061.           Document.FormatStyle[12] := tOptions.ColorInvisibleStyle;
  5062.      if tOptions.ColorSelectionBack <> '' then
  5063.           Document.FormatBackcolor[13] := HTMLToColor(tOptions.ColorSelectionBack);
  5064.      if tOptions.ColorSelectionText <> '' then
  5065.           Document.FormatTextcolor[13] := HTMLToColor(tOptions.ColorSelectionText);
  5066.      if tOptions.ColorSelectionStyle > -1 then
  5067.           Document.FormatStyle[13] := tOptions.ColorSelectionStyle;
  5068.      //if tOptions.ColorLineNoText <> '' then
  5069.      //     Document.FormatTextcolor[14] := HTMLToColor(tOptions.ColorLineNoText);
  5070.      if tOptions.ColorLineNoStyle > -1 then
  5071.           Document.FormatStyle[14] := tOptions.ColorLineNoStyle;
  5072.      //if tOptions.ColorCollapsedBack <> '' then
  5073.      //     Document.FormatBackcolor[15] := HTMLToColor(tOptions.ColorCollapsedBack);
  5074.      //if tOptions.ColorCollapsedText <> '' then
  5075.      //     Document.FormatTextcolor[15] := HTMLToColor(tOptions.ColorCollapsedText);
  5076.      if tOptions.ColorCollapsedStyle > -1 then
  5077.           Document.FormatStyle[15] := tOptions.ColorCollapsedStyle;
  5078.  
  5079.      //if tOptions.ColorWhiteSpaceBack <> '' then
  5080.      //     Document.Backcolor := HTMLToColor(tOptions.ColorWhiteSpaceBack);
  5081.      //if tOptions.ColorWhiteSpaceText <> '' then
  5082.      //    Document.TextColor := HTMLToColor(tOptions.ColorWhiteSpaceText);
  5083. end;
  5084.  
  5085. procedure TfrmDoc.spdSyntaxClick(Sender: TObject);
  5086. begin
  5087.     If (spdSyntax.Down) then
  5088.        rtfDoc.HighlightStyle := HTMLEDITVIEW_SYNTAX // kin 190997
  5089.     else
  5090.     begin
  5091.        if (spdTag.Down) then
  5092.           rtfDoc.HighlightStyle := HTMLEDITVIEW_TAGS
  5093.        else
  5094.           rtfDoc.HighlightStyle := HTMLEDITVIEW_NOTAGSYNTAX;
  5095.     end;
  5096.     UpdateTagColors;
  5097. end;
  5098.  
  5099. procedure TfrmDoc.spdTagClick(Sender: TObject);
  5100. begin
  5101.     If spdSyntax.Down then
  5102.        rtfDoc.HighlightStyle := HTMLEDITVIEW_SYNTAX // kin 190997
  5103.     else
  5104.     begin
  5105.        IF spdTag.Down then
  5106.           rtfDoc.HighlightStyle :=  HTMLEDITVIEW_TAGS
  5107.        else
  5108.           rtfDoc.HighlightStyle := HTMLEDITVIEW_NOTAGSYNTAX;
  5109.     end;
  5110.     //UpdateTagColors;
  5111. end;
  5112.  
  5113. procedure TfrmDoc.spdWordWrapClick(Sender: TObject);
  5114. begin
  5115.     rtfDoc.WordWrap := spdWordWrap.Down;
  5116. end;
  5117.  
  5118. procedure TfrmDoc.spdFieldsClick(Sender: TObject);
  5119. begin
  5120.     rtfDoc.DisplayAll := spdFields.Down;
  5121. end;
  5122.  
  5123. procedure TfrmDoc.spdInsertClick(Sender: TObject);
  5124. begin
  5125.     rtfDoc.Overwrite := spdInsert.Down;
  5126. end;
  5127.  
  5128. procedure TfrmDoc.spdFormatClick(Sender: TObject);
  5129. begin
  5130.     ToggleFileFormat;
  5131. end;
  5132.  
  5133. function TfrmDoc.PublishFields : Integer;
  5134. var
  5135.     sText: String;
  5136.     iChanges : Integer;
  5137. begin
  5138.     iChanges := 0;
  5139.     sText := PublishText(Document.Text, 'PUBLISH', sDocFileName, iChanges);
  5140.     Result := iChanges;
  5141.     if (Length(sText) > 0) and (sText <> Document.Text) then
  5142.         Document.Text := sText;
  5143.     {else
  5144.         MessageDlg('No Template fields found.', mtInformation, [mbOK], 0);}
  5145. end;
  5146.  
  5147. procedure TfrmDoc.PublishAutoFields;
  5148. var
  5149.     sText: String;
  5150.     iChanges : Integer;
  5151. begin
  5152.     iChanges := 0;
  5153.     sText := PublishText(Document.Text, 'CREATE', sDocFileName, iChanges);
  5154.     if (Length(sText) > 0) and (sText <> Document.Text) then
  5155.         Document.Text := sText;
  5156. end;
  5157.  
  5158. procedure TfrmDoc.InsertPublishField;
  5159. begin
  5160.     application.createform(TfrmPublishField, frmPublishField);
  5161.     if frmpublishfield.ShowModal = mrOK then
  5162.         addtext(frmpublishfield.PublishField, '', true);
  5163. end;
  5164.  
  5165. function TfrmDoc.GetTagAtScreenCoords(tPos: TPoint): String;
  5166. var
  5167.     tElement: Variant;
  5168.     iStart: Integer;    //iEnd: Integer;
  5169.     iPos: Integer;
  5170.     P{, Q}: TPoint; {Hint}
  5171. begin
  5172.     Result := '';
  5173.     //P := rtfDoc.ScreenToClient(tPos);
  5174.     P := tPos;
  5175.     Windows.ScreenToClient(rtfDoc.HWnd, P);
  5176.  
  5177.     iPos := rtfDoc.FindPositionFromPoint(P.X, P.Y);
  5178.  
  5179.     if iPos < Document.Length then
  5180.     begin
  5181.       tElement := Document.GetElementAt(iPos, iStart);
  5182.       if tElement.Type = HTMLSYNTAXELEMENT_TAG then
  5183.       begin
  5184.           Result := Document.GetTextRange(iStart, iStart + tElement.Length);
  5185.       end;
  5186.     end;
  5187. end;
  5188.  
  5189. procedure TfrmDoc.popEditColorClick(Sender: TObject);
  5190. var
  5191.    dlgColour: TfrmColorPicker;
  5192.    CurrentColor : TColor;
  5193. begin
  5194.     dlgColour := TfrmColorPicker.create(nil);
  5195.     try
  5196.        CurrentColor := HTMLToColor(SelText);
  5197.        dlgColour.SetDefaultColour(CurrentColor);
  5198.        if dlgColour.Showmodal = idOK then
  5199.        begin
  5200.            CurrentColor := dlgColour.color;
  5201.            SelText := '#' + GetHexColourStr(CurrentColor);
  5202.        end;
  5203.     finally
  5204.        dlgcolour.free;
  5205.        Application.OnShowhint := MainForm.AppOnShowHint;
  5206.     end;
  5207.  
  5208. end;
  5209.  
  5210. function TfrmDoc.GetNextWordPos(iPos : Integer) : Integer;
  5211. begin
  5212.      result := Document.GetNextWordPos(iPos);
  5213. end;
  5214.  
  5215. function TfrmDoc.GetPrevWordPos(iPos : Integer) : Integer;
  5216. begin
  5217.    result := Document.GetPrevWordPos(iPos);
  5218. end;
  5219.  
  5220. function TfrmDoc.GetNextLinePos(iPos : Integer) : Integer;
  5221. begin
  5222.   result := Document.GetNextLinePos(iPos);
  5223. end;
  5224.  
  5225. function TfrmDoc.GetPrevLinePos(iPos : Integer) : Integer;
  5226. begin
  5227.   result := Document.GetPrevLinePos(iPos);
  5228. end;
  5229.  
  5230. procedure TfrmDoc.ReplaceText(iStartPos, iLength : Integer; sReplaceText : String);
  5231. begin
  5232.      Document.ReplaceText(iStartPos, iLength, sReplaceText);
  5233. end;
  5234.  
  5235. procedure TfrmDoc.Reparse;
  5236. begin
  5237.      Document.Reparse; 
  5238. end;
  5239.  
  5240. procedure TfrmDoc.spdGutterClick(Sender: TObject);
  5241. begin
  5242.    try
  5243.     rtfDoc.Enabled := False;
  5244.     if spdGutter.Down then
  5245.     begin
  5246.         if tOptions.LineGutter then
  5247.         begin
  5248.              rtfDoc.IndentSize := iBookmarkWidth + (tOptions.LineGutterNumber * rtfDoc.GutterFontWidth);//LINE_GUTTER_SIZE;
  5249.              rtfDoc.ShowLineNumber := True;
  5250.         end
  5251.         else
  5252.         begin
  5253.              rtfDoc.IndentSize := iBookmarkWidth + rtfDoc.GutterFontWidth; //NO_LINE_GUTTER_SIZE;
  5254.              rtfDoc.ShowLineNumber := False;
  5255.         end;
  5256.         rtfDoc.LeftMarginVisible := True;
  5257.     end
  5258.     else
  5259.     begin
  5260.         rtfDoc.IndentSize := rtfDoc.GutterFontWidth;//NO_GUTTER_SIZE;
  5261.         rtfDoc.ShowLineNumber := False;
  5262.         rtfDoc.LeftMarginVisible := False;
  5263.     end;
  5264.    finally
  5265.     rtfDoc.Enabled := True;
  5266.    end;
  5267. end;
  5268.  
  5269. function TfrmDoc.GenerateTable(sTabledata : String) : String;
  5270. var
  5271.    i,j : Integer;
  5272.    strRows : TStringList;
  5273.    strCells : TStringList;
  5274.    sHTML : String;
  5275. const
  5276.      OPENROW : String = '<TR>';
  5277.      CLOSEROW : String = '</TR>';
  5278.      OPENCELL : String = '<TD>';
  5279.      CLOSECELL : String = '</TD>';
  5280.      TAB = #9;
  5281. begin
  5282.      strRows := TStringList.Create;
  5283.      strCells := TStringList.Create;
  5284.      sHTML := '<TABLE BORDER="1">' + #13#10;
  5285.      try
  5286.         ParseLine(sTabledata, #13#10, strRows);
  5287.         For i := 0 to strRows.Count - 1 do
  5288.         begin
  5289.              sHTML := sHTML + Tab + OPENROW + #13#10;
  5290.              ParseLine(strRows.Strings[i], Tab, strCells);
  5291.              For j := 0 to strCells.Count -1 do
  5292.              begin
  5293.                   sHTML := sHTML + Tab + Tab + OPENCELL + strCells.Strings[j] + CLOSECELL + #13#10;
  5294.              end;
  5295.              sHTML := sHTML + Tab + CLOSEROW + #13#10;
  5296.         end;
  5297.         sHTML := sHTML + '</TABLE>' + #13#10;
  5298.      except
  5299.      end;
  5300.      result := sHTML;
  5301. end;
  5302.  
  5303. procedure TfrmDoc.popMainHREFClick(Sender: TObject);
  5304. begin
  5305.      mOpenFileName(popMainHref.Hint);
  5306. end;
  5307.  
  5308. procedure TfrmDoc.PasteFromClipboard(Key : word);
  5309. var
  5310.    iRow : Integer;
  5311. begin
  5312.      iRow := 0;
  5313.      Case Key of
  5314.         49 : iRow := 1;
  5315.         50 : iRow := 2;
  5316.         51 : iRow := 3;
  5317.         52 : iRow := 4;
  5318.         53 : iRow := 5;
  5319.         54 : iRow := 6;
  5320.         55 : iRow := 7;
  5321.         56 : iRow := 8;
  5322.         57 : iRow := 9;
  5323.      end;
  5324.      if MainForm.strClipboard.Objects[1,iRow] <> Nil then
  5325.         SelText := (MainForm.strClipboard.Objects[1,iRow] as TClipboardString).sItem;
  5326. end;
  5327.  
  5328. procedure TfrmDoc.CopyToClipboard(Key : word);
  5329. var
  5330.    iRow : Integer;
  5331.    newString : TClipboardString;
  5332. begin
  5333.    iRow := 0;
  5334.    Case Key of
  5335.       49 : iRow := 1;
  5336.       50 : iRow := 2;
  5337.       51 : iRow := 3;
  5338.       52 : iRow := 4;
  5339.       53 : iRow := 5;
  5340.       54 : iRow := 6;
  5341.       55 : iRow := 7;
  5342.       56 : iRow := 8;
  5343.       57 : iRow := 9;
  5344.    end;
  5345.    if Pos(#13#10, SelText) > 0 then
  5346.       MainForm.strClipboard.Cells[1,iRow] := Copy(SelText, 0, Pos(#13#10, SelText)-1)
  5347.    else
  5348.       MainForm.strClipboard.Cells[1,iRow] := SelText;
  5349.    newString := TClipboardString.Create;
  5350.    newString.sItem := SelText;
  5351.    MainForm.strClipboard.Objects[1,iRow] := newString;
  5352. end;
  5353.  
  5354. procedure TfrmDoc.ShowThesaurus;
  5355. begin
  5356.      Application.CreateForm(TfrmThesaurus, frmThesaurus);
  5357.      if SelLength = 0 then
  5358.         rtfDoc.SelectWordAtPos(SelStart);
  5359.      frmThesaurus.sWord := SelText;
  5360.      //Status('Searching for selected word. This may take a few moments.');
  5361.      if frmThesaurus.ShowModal = mrOk then
  5362.      begin
  5363.         SelText := frmThesaurus.sWord;
  5364.      end;
  5365.      frmThesaurus.Release;
  5366. end;
  5367.  
  5368. function TfrmDoc.GetBookmarks : String;
  5369. var
  5370.    i : Integer;
  5371.    iDocumentCount : Integer;
  5372. begin
  5373.      iDocumentCount := rtfDoc.BookmarkCount -1;
  5374.      for i := 0 to iDocumentCount do
  5375.      begin
  5376.           Result := Result + rtfDoc.BookmarkName[i] + ',';
  5377.      end;
  5378. end;
  5379.  
  5380. procedure TfrmDoc.GotoBookmark(sBookmark : String);
  5381. begin
  5382.      try
  5383.         rtfDoc.GotoBookmark(sBookMark);
  5384.      except
  5385.      end;
  5386. end;
  5387.  
  5388. function TfrmDoc.GetCurrentLine : Integer;
  5389. var
  5390.    iCol, iRow : Integer;
  5391. begin
  5392.   Result := 0;
  5393.   try
  5394.         rtfDoc.FindCoordinateFromPosition(SelEnd, iCol, iRow);
  5395.         result := iRow + 1;
  5396.   except
  5397.   end;
  5398. end;
  5399.  
  5400. function TfrmDoc.GetLinePosition(iLine : Integer) : Integer;
  5401. begin
  5402.      result := -1;
  5403.      if (iLine > -1) and (iLine < Document.LineCount) then
  5404.      begin
  5405.           result := Document.LinePos(iLine);
  5406.      end;
  5407. end;
  5408.  
  5409. function TfrmDoc.GetNextElementPos(iType : Integer; iStart: Integer): Integer;
  5410. var
  5411.     //sResult: String; //-- Sav hint
  5412.     iCount: Integer;
  5413.     tElement: Variant;
  5414. begin
  5415.     Result := -1;
  5416.     tElement := Document.GetElementAt(iStart, iStart);
  5417.     iStart := iStart + tElement.Length;
  5418.     iCount := iStart;
  5419.     while iCount < Document.Length - 1 do
  5420.     begin
  5421.         try
  5422.             tElement := Document.GetElementAt(iCount, iStart);
  5423.             if tElement.Type <> iType then
  5424.                 iCount := iCount + tElement.Length
  5425.             else
  5426.             begin
  5427.                    Result := iStart;
  5428.                 if Result > -1 then
  5429.                     iCount := Document.Length
  5430.                 else
  5431.                     iCount := iCount + tElement.Length - 1;
  5432.             end;
  5433.         except
  5434.         end;
  5435.     end;
  5436. end;
  5437.  
  5438.  
  5439. function TfrmDoc.GetPreviousElementPos(iType : Integer; iStart : Integer) : Integer;
  5440. var
  5441.     //sResult: String; //-- Sav hint
  5442.     iCount: Integer;
  5443.     tElement: Variant;
  5444. begin
  5445.     Result := -1;
  5446.     tElement := Document.GetElementAt(iStart, iStart);
  5447.     Dec(iStart);
  5448.     iCount := iStart;
  5449.     while iCount > 0 do
  5450.     begin
  5451.         try
  5452.             tElement := Document.GetElementAt(iCount, iStart);
  5453.             if tElement.Type <> iType then
  5454.                 iCount := iCount - tElement.Length
  5455.             else
  5456.             begin
  5457.                    Result := iStart;
  5458.                 if Result > -1 then
  5459.                     iCount := 0
  5460.                 else
  5461.                     iCount := iCount - (tElement.Length + 1);
  5462.             end;
  5463.         except
  5464.         end;
  5465.     end;
  5466. end;
  5467.  
  5468. procedure TfrmDoc.FindMatchingCharacter(iPosition : Integer);
  5469. var
  5470.     //tElement: Variant;
  5471.     iStart : Integer;
  5472. begin
  5473.     iStart := rtfDoc.GetMatchChar(iPosition);
  5474.     rtfDoc.SetSelection(iStart, iStart);
  5475. end;
  5476.  
  5477. function TfrmDoc.DocSaveAsRemote: Boolean;
  5478. var
  5479.   dlgRemote: TfrmRemoteDlg;
  5480.   sFile: String;
  5481. begin
  5482.   dlgRemote := TfrmRemoteDlg.Create(Application);
  5483.   try
  5484.     dlgRemote.DlgType := DlgSave;
  5485.     dlgRemote.Filter := HTML_FILTER_;
  5486.     dlgRemote.DefaultExt := 'htm';
  5487.     dlgRemote.FilterIndex := 0;
  5488.  
  5489.     {-= Create a tmp file and write to it... =-}
  5490.     sFile := FilePath(GetTempDirectory, ('~hd1201.zzz'));
  5491.     Document.SaveToFile(sFile);
  5492.     dlgRemote.FileName := sFile;
  5493.     if dlgRemote.ShowModal <> idCancel then
  5494.     begin
  5495.       bInternet := True;
  5496.       sInternetFileName := dlgRemote.RemoteFileName;
  5497.       tInternetServer := dlgRemote.InternetServer;
  5498.       sDocFileName := GetTempDirectory;
  5499.       sDocFileName := FilePath(sDocFileName, ExtractFileName(dlgRemote.FileName));
  5500.       {MessageDlg('Remote file ' + sInternetFileName + ' succesfully saved.',
  5501.                    mtConfirmation, [mbOK], 0);}
  5502.       Caption := dlgRemote.RemoteFileName;
  5503.       //MainForm.Draw(True);
  5504.       bDocDirty := False;
  5505.       Result := True;
  5506.       MDI.UpdateTabName(Self, sInternetFileName);
  5507.       //tProject.UpdateSniffer(MDI.MDIChildIndex(Self), sInternetFileName);
  5508.       if tOptions.SaveBrowserRefresh then
  5509.           DocPreviewWithLastBrowser;
  5510.       HideToolbarShit(False);
  5511.     end
  5512.     else
  5513.       Result := False;
  5514.   finally
  5515.     dlgRemote.Free;
  5516.   end;
  5517. end;
  5518.  
  5519.  
  5520. procedure TfrmDoc.DocBody;
  5521. var
  5522.     strBody : TStringList;
  5523.     sResult : String;
  5524.     iPos : Integer;
  5525. begin
  5526.     strBody := TStringList.Create;
  5527.     try
  5528.       SniffText(Text, '<body', '>', strBody, True);
  5529.       if strBody.Count >= 0 then
  5530.         try
  5531.             sResult := strBody.Strings[0];
  5532.             iPos := StrToInt(copy(sResult, 0, (Pos(',', sResult)-1)));// + Length(sResult);
  5533.             sResult := copy(sResult, (Pos(',', sResult)+1), Length(sResult));
  5534.             iPos := iPos + Length(sResult);
  5535.             SetCursorPos(iPos);
  5536.         except
  5537.             SetCursorPos(Find('<BODY', 0, False, False) + 7);
  5538.         end;
  5539.     finally
  5540.         strBody.Free;
  5541.     end;
  5542. end;
  5543.  
  5544. function TfrmDoc.GetDocumentStorageHandle: HGlobal;
  5545. var
  5546.   hMem: HGlobal;
  5547. begin
  5548.   Result := 0;
  5549.   if rtfDoc.SaveExtraInfoToMemory(hMem) then
  5550.     Result := hMem;
  5551. end;
  5552.  
  5553. procedure TfrmDoc.LoadStorageMemory(hMem: HGlobal);
  5554. begin
  5555.   rtfDoc.LoadExtraInfoFromMemory(hMem, GlobalSize(hMem));
  5556.  
  5557. end;
  5558.  
  5559. procedure TfrmDoc.FormKeyUp(Sender: TObject; var Key: Word;
  5560.   Shift: TShiftState);
  5561. var
  5562.     pt : TPoint;
  5563. begin
  5564.     //ShowMessage(Format('%d', [SelStart]));  // -- Test
  5565.     if (ssCtrl in Shift) and (Key = 9) then
  5566.        GotFocus
  5567.     //windows right click key
  5568.     else if (key = 93) then
  5569.     begin
  5570.        rtfDoc.ScrollCaretToView;
  5571.        rtfDoc.FindPointFromPosition(SelEnd, pt.X, pt.Y);
  5572.        pt.Y := pt.Y - rtfDoc.EditFont.Height;
  5573.        rtfDoc.HideSyntaxPicker;
  5574.        //pt := ClientToScreen(pt);
  5575.        MainViewRightClick(pt.x, pt.y);
  5576.     end
  5577.     //Delete key does not automatically make the document dirty
  5578.     else if (Key = 8) or (key = 46)  then
  5579.     begin
  5580.         bDocDirty := True;
  5581.         MainForm.DirtyBird(True);
  5582.         HideToolbarShit(False);
  5583.         //MainForm.HideShit;
  5584.     end;
  5585.  
  5586. end;
  5587.  
  5588. procedure TfrmDoc.popHideGutterClick(Sender: TObject);
  5589. begin
  5590.     spdGutter.Down := False;
  5591.     spdGutterClick(Self);
  5592. end;
  5593.  
  5594. procedure TfrmDoc.popShowPawsClick(Sender: TObject);
  5595. begin
  5596.     rtfDoc.GutterBitmapVisible := Not(rtfDoc.GutterBitmapVisible);
  5597. end;
  5598.  
  5599. procedure TfrmDoc.popLine0Click(Sender: TObject);
  5600. begin
  5601.     rtfDoc.IndentSize := iBookMarkWidth + rtfDoc.GutterFontWidth;
  5602.     tOptions.LineGutter := False;
  5603.     rtfDoc.ShowLineNumber := False;
  5604. end;
  5605.  
  5606. procedure TfrmDoc.popLine1Click(Sender: TObject);
  5607. begin
  5608.    tOptions.LineGutterNumber := 1;
  5609.    rtfDoc.IndentSize := iBookMarkWidth +  (1 * rtfDoc.GutterFontWidth);
  5610.    tOptions.LineGutter := True;
  5611.    rtfDoc.ShowLineNumber := True;
  5612. end;
  5613.  
  5614. procedure TfrmDoc.popLine2Click(Sender: TObject);
  5615. begin
  5616.    tOptions.LineGutterNumber := 2;
  5617.    rtfDoc.IndentSize := iBookMarkWidth +  (2 * rtfDoc.GutterFontWidth);
  5618.    tOptions.LineGutter := True;
  5619.    rtfDoc.ShowLineNumber := True;
  5620. end;
  5621.  
  5622. procedure TfrmDoc.popLine3Click(Sender: TObject);
  5623. begin
  5624.    tOptions.LineGutterNumber := 3;
  5625.    rtfDoc.IndentSize := iBookMarkWidth +  (3 * rtfDoc.GutterFontWidth);
  5626.    tOptions.LineGutter := True;
  5627.    rtfDoc.ShowLineNumber := True;
  5628. end;
  5629.  
  5630. procedure TfrmDoc.popLine4Click(Sender: TObject);
  5631. begin
  5632.    tOptions.LineGutterNumber := 4;
  5633.    rtfDoc.IndentSize := iBookMarkWidth +  (4 * rtfDoc.GutterFontWidth);
  5634.    tOptions.LineGutter := True;
  5635.    rtfDoc.ShowLineNumber := True;
  5636. end;
  5637.  
  5638. procedure TfrmDoc.popPSPClick(Sender: TObject);
  5639. var
  5640.     sFileName : String;
  5641. begin
  5642.     rtfDoc.SetSelection(tCurrentElement.iStart, tCurrentElement.iLength);
  5643.     sFileName := GetAttribute(SelText,'SRC');
  5644.     if Length(sFileName) > 0 then
  5645.     begin
  5646.         if Pos('file://', sFileName) > 0 then
  5647.             sFileName := URLToFile(sFileName);
  5648.         sFileName := RelativeToAbsolute(sDocFileName, sFileName);
  5649.         if FileExists(sFilename) then
  5650.             RunPaintShop(sFileName)
  5651.         else
  5652.             MessageDlg('The image ' + sFileName + ' could not be found.', mtError, [mbOK], 0);
  5653.     end;
  5654. end;
  5655. procedure TfrmDoc.mnuRelToAbsClick(Sender: TObject);
  5656. begin
  5657.     try
  5658.         DocRelToAbs;
  5659.     except
  5660.     end; 
  5661. end;
  5662.  
  5663. procedure TfrmDoc.mnuAbsToRelClick(Sender: TObject);
  5664. begin
  5665.     try
  5666.         DocAbsToRel;
  5667.     except
  5668.     end;
  5669. end;
  5670.  
  5671. procedure TfrmDoc.mnuConvertLowerClick(Sender: TObject);
  5672. begin
  5673.     try
  5674.         DocConvertCase(False);
  5675.     except
  5676.     end;
  5677. end;
  5678.  
  5679.  
  5680.  
  5681. procedure TfrmDoc.mnuConvertUpperClick(Sender: TObject);
  5682. begin
  5683.     try
  5684.         DocConvertCase(True);
  5685.     except
  5686.     end;
  5687. end;
  5688.  
  5689. procedure TfrmDoc.mnuTagsLowercaseClick(Sender: TObject);
  5690. begin
  5691.   try
  5692.     DocConvertTagCase(False, False);
  5693.   except
  5694.   end;
  5695. end;
  5696.  
  5697. procedure TfrmDoc.mnuTagsUppercaseClick(Sender: TObject);
  5698. begin
  5699.   try
  5700.     DocConvertTagCase(False, True);
  5701.   except
  5702.   end;
  5703. end;
  5704.  
  5705. procedure TfrmDoc.mnuTableClick(Sender: TObject);
  5706. begin
  5707.     try
  5708.         SelText := GenerateTable(SelText);
  5709.     except
  5710.     end;
  5711. end;
  5712.  
  5713.  
  5714. procedure TfrmDoc.mnuBListClick(Sender: TObject);
  5715. begin
  5716.     try
  5717.         InsertList;
  5718.     except
  5719.     end;
  5720. end;
  5721.  
  5722. procedure TfrmDoc.SetupMacroMenu;
  5723. var
  5724.     menNewItem : TMenuItem;
  5725.     pCategory : ^TMenuItem;
  5726.     iCount : Integer;
  5727.     strMacros : TStringList;
  5728. begin
  5729.     strMacros := TStringList.Create;
  5730.     try
  5731.        //Delete all the existing macro list items
  5732.        while mnuMacros.Count > 0 do
  5733.            mnuMacros.Delete(0);
  5734.     except
  5735.     end;
  5736.     try
  5737.        strMacros.LoadfromFile(sAppPath+'HDMacros.mac');
  5738.        if strMacros.Count > 0 then
  5739.        begin
  5740.           New(pCategory);
  5741.           pCategory^ := mnuMacros;
  5742.           for iCount := 0 to strMacros.Count -1 do
  5743.           begin
  5744.                menNewItem := TMenuItem.Create(popViewMain);
  5745.                if Pos('{', strMacros.Strings[iCount]) = 0 then
  5746.                begin
  5747.                    menNewItem.Caption := strMacros.Strings[iCount];
  5748.                    mnuMacros.Insert(mnuMacros.Count, menNewItem);
  5749.                    pCategory^ := menNewItem;
  5750.                end
  5751.                else
  5752.                begin
  5753.                   menNewItem.OnClick := MacroMenuClick;
  5754.                   menNewItem.Caption := chopafter(chopbefore(strMacros.strings[iCount],'}}{{'),'}{');
  5755.                   pCategory^.Insert(pCategory^.Count, menNewItem);
  5756.                end;
  5757.                mnuMacros.Enabled := True;
  5758.           end;
  5759.        end;
  5760.     finally
  5761.         strMacros.Free;
  5762.     end;
  5763. end;
  5764.  
  5765.  
  5766. procedure TfrmDoc.MacroMenuClick(Sender : TObject);
  5767. var
  5768.     iMacroPos : Integer;
  5769.     strMacros : TStringList;
  5770.     sMacroName : String;
  5771. begin
  5772.     strMacros := TStringList.Create;
  5773.     try
  5774.        strMacros.LoadfromFile(sAppPath+'HDMacros.mac');
  5775.        iMacroPos := -1;
  5776.        sMacroName := (Sender as TMenuItem).Caption;
  5777.        repeat
  5778.            inc(iMacroPos);
  5779.        until (pos(('}{'+sMacroName+'}}{{'),strMacros.strings[iMacroPos])>0) or (iMacroPos=strMacros.count-1);
  5780.        if iMacroPos<=strMacros.count-1 then
  5781.        begin
  5782.             strMacros.strings[iMacroPos] := ReplaceString(strMacros.strings[iMacroPos], #30, #13#10);
  5783.             SelText := GetMacroBeforeText(strMacros.strings[iMacroPos]) + SelText + GetMacroAfterText(strMacros.strings[iMacroPos]);
  5784.             SetSelection(SelEnd, 0);
  5785.        end;
  5786.     finally
  5787.     end;
  5788. end;
  5789.  
  5790. procedure TfrmDoc.rtfDocRequestURL(Sender: TObject;
  5791.   var bDispatched: WordBool; var strURL: WideString;
  5792.   var bAccepted: WordBool);
  5793. var
  5794.     sInitialDir : String;
  5795. begin
  5796.     if tOptions.DlgCurrentDir then
  5797.         sInitialDir := tOptions.LastHTMLDir
  5798.      else
  5799.         sInitialDir := tOptions.DocumentDirectory;
  5800.     DisplayFileDialog(HTML_FILTER_, sInitialDir, bDispatched, strURL, bAccepted);
  5801. end;
  5802.  
  5803. procedure TfrmDoc.DisplayFileDialog(sFilter, sInitialDir : String; var Dispatched : WordBool; var Name : WideString; var Accepted : WordBool);
  5804. begin
  5805.      Dispatched := True;
  5806.      Name := ShowDialogs(MainForm, sFilter, Name, sInitialDir);
  5807.      if Name <> '' then
  5808.         Accepted := True
  5809.      else
  5810.         Accepted := False;
  5811. end;
  5812.  
  5813. procedure TfrmDoc.rtfDocRequestFont(Sender: TObject;
  5814.   var bDispatched: WordBool; var strFont: WideString;
  5815.   var bAccepted: WordBool);
  5816. begin
  5817.    bDispatched := True;
  5818.    bAccepted := False;
  5819.    Application.CreateForm(TfrmFontDlg, frmFontDlg);
  5820.    try
  5821.       frmFontDlg.ShowModal;
  5822.       if frmFontDlg.ModalResult = mrOK then
  5823.       begin
  5824.            bAccepted := True;
  5825.            strFont := frmFontDlg.HTMLFont.Name;
  5826.       end;
  5827.    finally
  5828.        frmFontDlg.Free;
  5829.    end;
  5830. end;
  5831.  
  5832. procedure TfrmDoc.rtfDocRequestSound(Sender: TObject;
  5833.   var bDispatched: WordBool; var strSound: WideString;
  5834.   var bAccepted: WordBool);
  5835. begin
  5836.     DisplayFileDialog(SOUND_FILTER, tOptions.DocumentDirectory, bDispatched, strSound, bAccepted);
  5837. end;
  5838.  
  5839. procedure TfrmDoc.rtfDocRequestPicture(Sender: TObject;
  5840.   var bDispatched: WordBool; var strPicture: WideString;
  5841.   var bAccepted: WordBool);
  5842. var
  5843.     sInitialDir : String;
  5844. begin
  5845.      if tOptions.DlgCurrentDir then
  5846.         sInitialDir := tOptions.LastGraphicsDir
  5847.      else
  5848.         sInitialDir := tOptions.GraphicsDirectory;
  5849.      DisplayFileDialog(GRAPHICS_FILTER, sInitialDir, bDispatched, strPicture, bAccepted);
  5850. end;
  5851.  
  5852. procedure TfrmDoc.rtfDocRequestJava(Sender: TObject;
  5853.   var bDispatched: WordBool; var strJava: WideString;
  5854.   var bAccepted: WordBool);
  5855. begin
  5856.     DisplayFileDialog(ALLFILES_FILTER, tOptions.DocumentDirectory,  bDispatched, strJava, bAccepted);
  5857. end;
  5858.  
  5859. procedure TfrmDoc.rtfDocRequestHTML(Sender: TObject;
  5860.   var bDispatched: WordBool; var strHTML: WideString;
  5861.   var bAccepted: WordBool);
  5862. var
  5863.     sInitialDir : String;
  5864. begin
  5865.     if tOptions.DlgCurrentDir then
  5866.         sInitialDir := tOptions.LastHTMLDir
  5867.     else
  5868.         sInitialDir := tOptions.DocumentDirectory;
  5869.     DisplayFileDialog(HTML_FILTER_, sInitialDir, bDispatched, strHTML, bAccepted);
  5870. end;
  5871.  
  5872. procedure TfrmDoc.rtfDocRequestDirectory(Sender: TObject;
  5873.   var bDispatched: WordBool; var strDirectory: WideString;
  5874.   var bAccepted: WordBool);
  5875. begin
  5876.     bDispatched := True;
  5877.     bAccepted := False;
  5878.     Application.CreateForm(TfrmDirList, frmDirList);
  5879.     frmDirList.ptDirTree.SelectedPathName := strDirectory;
  5880.     frmDirList.ShowModal;
  5881.     if frmDirList.ModalResult <> mrOk  then
  5882.     begin
  5883.         bAccepted := True;
  5884.         strDirectory := frmDirList.ptDirTree.SelectedPathName
  5885.     end;
  5886.     frmDirList.Free;
  5887. end;
  5888.  
  5889. procedure TfrmDoc.HideSyntaxPicker;
  5890. begin
  5891.     rtfDoc.HideSyntaxPicker;
  5892. end;
  5893. procedure TfrmDoc.rtfDocSyntaxObjectChanged(Sender: TObject;
  5894.   nType: Smallint; const strPrimary, strSecondary: WideString);
  5895. begin
  5896.     if Assigned(MainForm.tpnlPSheet) then
  5897.         MainForm.propSheetObjectChanged(Sender, nType, strPrimary, strSecondary); 
  5898. end;
  5899.  
  5900. procedure TfrmDoc.mnuStripTagsClick(Sender: TObject);
  5901. begin
  5902.     StripTags;
  5903. end;
  5904.  
  5905. procedure TfrmDoc.DisplayGutterPopup(X, Y : Integer);
  5906. var
  5907.     gutterItems : Array[0..2] of TMenuItem;
  5908.     NumberItems : Array[0..4] of TMenuItem;
  5909.     popGutter : TPopupMenu;
  5910.     P, Q: TPoint;
  5911. begin
  5912.        gutterItems[0] := NewItem('&Hide Gutter', 0, False, True, popHideGutterClick, 0, 'popShowGutter');
  5913.        gutterItems[1] := NewItem('&Show &Paws', 0, False, True, popShowPawsClick, 0, 'popShowPaws');
  5914.  
  5915.        numberItems[0] := NewItem('&Not Shown', 0, False, True, popLine0Click, 0, 'popLine0');
  5916.        numberItems[1] := NewItem('&1 Number', 0, False, True, popLine1Click, 0, 'popLine1');
  5917.        numberItems[2] := NewItem('&2 Numbers', 0, False, True, popLine2Click, 0, 'popLine2');
  5918.        numberItems[3] := NewItem('&3 Numbers', 0, False, True, popLine3Click, 0, 'popLine3');
  5919.        numberItems[4] := NewItem('&4 Numbers', 0, False, True, popLine4Click, 0, 'popLine4');
  5920.  
  5921.        if rtfDoc.GutterBitmapVisible then
  5922.             gutterItems[1].Caption := 'Hide &Paws'
  5923.        else
  5924.             gutterItems[1].Caption := 'Show &Paws';
  5925.  
  5926.        if not(tOptions.LineGutter) then
  5927.            numberItems[0].Checked := True
  5928.        else if tOptions.LineGutterNumber = 1 then
  5929.            numberItems[1].Checked := True
  5930.        else if tOptions.LineGutterNumber = 2 then
  5931.            numberItems[2].Checked := True
  5932.        else if tOptions.LineGutterNumber = 3 then
  5933.            numberItems[3].Checked := True
  5934.        else if tOptions.LineGutterNumber = 4 then
  5935.            numberItems[4].Checked := True;
  5936.  
  5937.        gutterItems[2] := NewSubMenu('&Line Numbers', 0, 'popLineNumbers', numberItems);
  5938.        popGutter := NewPopupMenu(Self, 'popGutter', paLeft, True, gutterItems);
  5939.  
  5940.        P := Point(X, Y);
  5941.        Q := rtfDoc.ClientToScreen(P);
  5942.        popGutter.PopUp(Q.X, Q.Y);
  5943.        Application.ProcessMessages;
  5944.        popGutter.Free;
  5945. end;
  5946.  
  5947. procedure TfrmDoc.DocQuickColor(sColor : String);
  5948. begin
  5949.     //called from quick color form
  5950.     SelText := sColor;
  5951. end;
  5952.  
  5953. procedure TfrmDoc.rtfDocRequestColor(Sender: TObject;
  5954.   var bDispatched: WordBool; var Color: Cardinal; var bAccepted: WordBool);
  5955. var
  5956.    dlgColour: TfrmColorPicker;
  5957. begin
  5958.     dlgColour := TfrmColorPicker.create(nil);
  5959.     bDispatched := True;
  5960.     try
  5961.        dlgColour.SetDefaultColour(Color);
  5962.        if dlgColour.showmodal = idOK then
  5963.        begin
  5964.            bAccepted := True;
  5965.            Color := dlgColour.color;
  5966.        end;
  5967.      finally
  5968.        dlgcolour.free;
  5969.        Application.OnShowhint := MainForm.AppOnShowHint;
  5970.     end;
  5971. end;
  5972.  
  5973. procedure TfrmDoc.WMMOVE(var Message: TWMMOVE);
  5974. begin
  5975.     inherited;
  5976.     //InvalidateRect(ClientHandle, nil, True);
  5977. end;
  5978.  
  5979. procedure TfrmDoc.WMSIZE(var Message: TWMSIZE);
  5980. begin
  5981.     inherited;
  5982.     spdFormat.Left := panButtons.Width - SpdFormat.Width;
  5983.     lblDocWeight.Left := spdFormat.Left - lblDocWeight.Width;
  5984. end;
  5985.  
  5986. procedure TfrmDoc.btnShowButtonsClick(Sender: TObject);
  5987. begin
  5988.     ResizeRoverToolbar(not spdSyntax.Visible);
  5989.     tOptions.EditorToolbarLarge := spdSyntax.Visible;
  5990. end;
  5991.  
  5992. procedure TfrmDoc.RefreshDocumentWeight;
  5993. var
  5994.     iSize : Integer;
  5995. begin
  5996.     iSize := CalculateDocumentSize;
  5997.     if iSize < 1024 then
  5998.         lblDocWeight.caption := IntToStr(iSize) + ' Bytes '
  5999.     else
  6000.         lblDocWeight.Caption  := IntToStr(iSize div 1024)+'Kb ';
  6001. end;
  6002. procedure TfrmDoc.lblDocWeightMouseDown(Sender: TObject;
  6003.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  6004. begin
  6005.     if button = mbLeft then
  6006.         RefreshDocumentWeight;
  6007. end;
  6008.  
  6009. procedure TfrmDoc.ResizeRoverToolbar(bLargeView: Boolean);
  6010. begin
  6011.     if not bLargeView then
  6012.     begin
  6013.         spdSyntax.Visible := False;
  6014.         spdTag.Visible := False;
  6015.         spdGutter.Visible := False;
  6016.         spdWordWrap.Visible := False;
  6017.         spdFields.Visible := False;
  6018.         spdInsert.Visible := False;
  6019.         spdFormat.Visible := False;
  6020.         btnShowButtons.glyph.LoadFromResourceName(hInstance, 'bmpDocToolbarExpand');
  6021.         panButtons.Height := 8;
  6022.         btnShowButtons.Height := 8;
  6023.         btnShowButtons.Top := 0;
  6024.         lblDocWeight.Visible := False;
  6025.         //bevDocWeight.Visible := False;
  6026.     end
  6027.     else
  6028.     begin
  6029.         spdSyntax.Visible := True;
  6030.         spdTag.Visible := True;
  6031.         spdGutter.Visible := True;
  6032.         spdWordWrap.Visible := True;
  6033.         spdFields.Visible := True;
  6034.         spdInsert.Visible := True;
  6035.         spdFormat.Visible := True;
  6036.         btnShowButtons.glyph.LoadFromResourceName(hInstance, 'bmpDocToolbarCollapse');
  6037.         panButtons.Height := 23;
  6038.         btnShowButtons.Top := 1;
  6039.         btnShowButtons.Height := 22;
  6040.         lblDocWeight.Visible := True;
  6041.         //bevDocWeight.Visible := True;
  6042.     end;
  6043.  
  6044. end;
  6045.  
  6046. procedure TfrmDoc.popMainSmartPasteClick(Sender: TObject);
  6047. begin
  6048.     DocPasteLeftAligned;
  6049. end;
  6050.  
  6051. end.
  6052.  
  6053.